Making Minimalist Web Server in Assembly on Linux (x64)

  Рет қаралды 34,765

Nir Lichtman

Nir Lichtman

3 ай бұрын

In this video I will demonstrate how you can make a simple web server using x64 Assembly and Linux system calls.
I am planning to continue the POC from the video in the following Github project: github.com/nir9/fastws
Documentation I used in the video: flatassembler.net/docs.php?ar...

Пікірлер: 105
@jonfastofficial2460
@jonfastofficial2460 3 ай бұрын
This is straight up sorcery. The code didn’t use a single include, extern, or struct definition. Excellent work!
@Bunny99s
@Bunny99s 3 ай бұрын
@@yestechguy-fj9tm Right, but the point of frameworks and standard libraries is to abstract the implementation of the ABI away from the programmer so we get a unique interface that works the same regardless of the underlying architechture. So the actual syscall number and how the arguments are passed is handled by the library. Though when you know your target, of course you can directly issue the syscall. I haven't done any low level programming on modern systems. I've done a lot during the Win95/98/XP times :)
@skilz8098
@skilz8098 24 күн бұрын
@yestechguy-fj9tm It's even more fun when you design your own ISA & ABI...
@gatogordo4131
@gatogordo4131 3 ай бұрын
it's pretty hard to find hard core content like yours. I can learn a lot from your videos, keep going! Greetings from Brazil.
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks!
@fallout__boy1130
@fallout__boy1130 2 ай бұрын
This looks like sorcery, but sorcery is actually all the levels of abstractions uppon which we are used to develop. Very nice content
@ItsCOMMANDer_
@ItsCOMMANDer_ 3 ай бұрын
next: gas compatable
@NOPerative
@NOPerative 3 ай бұрын
Flip the registers and insert the appropriate tokens. Conversion to and from GAS is pretty simple.
@ItsCOMMANDer_
@ItsCOMMANDer_ 3 ай бұрын
also mormat elf is unnecessary i think@@NOPerative
@NOPerative
@NOPerative 3 ай бұрын
@@ItsCOMMANDer_ Yes. Format ELF is FAsm exclusive. The format directive is unnecessary with GAS and NAsm.
@Crux161
@Crux161 2 ай бұрын
I love how he shows what documentation to reference, and people still call it sorcery 😂
@shalinpather4198
@shalinpather4198 3 ай бұрын
Legendary. Keep up with the videos. A few of your videos taught me far more than two year's worth of Computer Science courses.
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks! I appreciate the compliment :)
@mrsquiggles1379
@mrsquiggles1379 3 ай бұрын
Really cool and creative how you derived addresses and call codes from C and injected that into assembly. Makes it more readable and easier to understand very impressive
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks :)
@Mauriciohse
@Mauriciohse 3 ай бұрын
Great video man, always so cool to see how things happen under the hood. Ty!
@anthonygayflor
@anthonygayflor Ай бұрын
Incredible work! I mainly work with JavaScript and when I used to hear people say C is high level it always left me bewildered. Now I understand.
@Bunny99s
@Bunny99s 3 ай бұрын
fasm is really a great and small assembler. I used it about 18 years ago to write a tiny keyboard hook dll which was just 2.5k in size. At that time Win98 / XP didn't had the low level hooks we have nowadays and keyboard / mouse hooks required a separate DLL which the OS injected into every application to process the hook in the active process space. Though afaik this dll doesn't work anymore. However I think the main reason is that i think it was an x86 (32bit) dll. Back in the day I used to write software with delphi and most applications where single file builds which is generally great for being portable. The keyboard hook dll was simply included as a resource and I unpacked it when it didn't exist yet. The dll was still quite large but this was mainly because of the import and export tables which require a certain memory alignment by windows.
@honeymak
@honeymak 3 ай бұрын
thx for all the heavy lifting of the pre-knowledge for this video to be made
@user-gh4lv2ub2j
@user-gh4lv2ub2j 3 ай бұрын
Thank you for your service sir.
@jsaenzMusic
@jsaenzMusic 3 ай бұрын
Bro......THIS is what I'm talking about! Thank you for this content!!!!
@twobob
@twobob 3 ай бұрын
very nice as always. thanks for the repo
@milk-it
@milk-it 2 ай бұрын
Very interesting and great job! One question: if you couldn't use the C/Python header files, where would you find the values and methodology?
@nirlichtman
@nirlichtman 2 ай бұрын
Another option instead of doing the trick I did with the GCC preprocessor and header files is to manually copy over the values from the header files to the Assembly, but notice that syscall numbers change between different processor architectures so make sure you are copying the correct numbers for your architecture. Another way is to locate these values from the Linux kernel source, for example here is sockaddr_in in the kernel source elixir.bootlin.com/linux/latest/source/include/uapi/linux/in.h#L256
@jamiepond
@jamiepond 3 ай бұрын
outstanding explantation.
@dj.yacine
@dj.yacine 3 ай бұрын
Always creative
@madwilliamflint
@madwilliamflint 3 ай бұрын
I love it!
@durimmiziraj4815
@durimmiziraj4815 2 ай бұрын
Great channel!
@kbsanders
@kbsanders 2 ай бұрын
Would it have been possible to create register aliases for the system call arguments? arg1 equ rdi arg2 equ rsi arg3 equ rdx arg4 equ r10 arg5 equ r8 arg6 equ r9
@savire.ergheiz
@savire.ergheiz 3 ай бұрын
Now lets create full scaleable enterprise app 😂
@dev.rahulgurjar
@dev.rahulgurjar 2 ай бұрын
Amazing 🤩
@AlexSmolyankin
@AlexSmolyankin 3 ай бұрын
Really nice. Especial how you combine constants from C with assembly. Could you make a video how you work with vim(as I understand you use wsl with vim). But how did you manage to run server on wsl and open page on windows? I mean does windows automatically forwards requests inside wsl?
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks! I have a playlist "Vim Tips" with videos about how I work with Vim, when I do Windows dev I work with Vim for Windows and when doing Linux dev I mostly work with Vim running on WSL. Yes, the request was automatically forwarded to WSL, I didn't configure anything special
@AlexSmolyankin
@AlexSmolyankin 3 ай бұрын
@@nirlichtmanThanks for full response. Will check you "Vim Tips"
@AMith-lv2cv
@AMith-lv2cv 3 ай бұрын
🔥🔥🔥🔥 wanna more and more
@pouf-dk3nq
@pouf-dk3nq 3 ай бұрын
This was so cool, btw shouldn't you have used close() to close the opened file descriptor ? and to get the syscalls values you can check a header in /usr/include/asm/unistd_64.h (as well as unistd_32.h)
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks! Yah I skipped doing cleanup/error checking to keep the video short (also have a disclaimer about this on the vid), but I added close in the code on Github. You can indeed get the syscall values directly from the header files as well (on my machine it has a different path), the idea of the preprocessor trick I did in the video is to automate this
@Kharzette
@Kharzette 3 ай бұрын
Amazed how you can do what I do with 2 huge monitors in a tiny little split up terminal window. 👍
@nirlichtman
@nirlichtman 3 ай бұрын
Yah I used to have a dual monitor setup as well but decided a couple of years ago to move back to single monitor due to neck strain
@R.B.
@R.B. 3 ай бұрын
I find that even with an UWQHD monitor, it's hard to find a good way to partition the screen so that it is better than dual screens. I really need a SUWQHD I think... or just keep using dual screens. At least the footprint of a single UWQHD is an improvement.
@forevervoyaging
@forevervoyaging 2 ай бұрын
While this is pure wizardry, your explanation is crystal clear and makes everything easy to follow. Outstanding work!
@plato4ek
@plato4ek 2 ай бұрын
Hey! I really love your work! It would be great, if you put the links to the docs you use in the description box, so one doesn't need to retype them.
@nirlichtman
@nirlichtman 2 ай бұрын
Thanks! added :)
@elyazidful
@elyazidful 3 ай бұрын
I like it !
@hidoHido-vm4en
@hidoHido-vm4en 2 ай бұрын
if i want to run this Minimalist web server in raspberry pi pico w for a simple iot on/off leds and some simple controls is that will be more challenging ?
@HP-gk7us
@HP-gk7us 2 ай бұрын
Love! ❤
@Bobby-sm3sy
@Bobby-sm3sy 2 ай бұрын
legend
@zazem4835
@zazem4835 3 ай бұрын
I LOVE THIS. Also wanna know how you navigate vim
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks! I have a playlist "Vim Tips" with information about that :)
@Kira_x86_64
@Kira_x86_64 3 ай бұрын
I am so used to using nasm that this looks foren to me... love the video though!
@nirlichtman
@nirlichtman 3 ай бұрын
I am also used to NASM but recently I started using FASM and I like it a lot more :)
@biohazardouszxellium
@biohazardouszxellium Ай бұрын
Based on your experience, in which scenario would be appropriate to use. NASM/FASM/MASM/etc? Subscribed by the way!
@nirlichtman
@nirlichtman Ай бұрын
Thanks! You mean which scenarios are appropriate to use Assembly in general? There are all kinds, for example early boot code for bootloaders, using in conjunction with C/C++ code since there are cases where using Assembly for certain parts is required to call certain specific instructions, or optimize a specific part, and of course in extreme cases you can even write full programs with Assembly - like Roller Coaster Tycoon :)
@biohazardouszxellium
@biohazardouszxellium Ай бұрын
@@nirlichtman Yea the famous game Roller Coaster Tycoon! I'm starting to re-learn C and NASM. Do you also have experience with microcontrollers?
@nirlichtman
@nirlichtman Ай бұрын
@@biohazardouszxellium Not a lot just playing a little with Arduino, but I definitely plan on learning some Arduino AVR assembly when I have more time, interesting subject!
@Trippie1400
@Trippie1400 2 ай бұрын
please make a video about creating a color theme for Vim 🙏
@llj0000
@llj0000 3 ай бұрын
Love this stuff bro, but please do xor rdx, rdx instead of mov rdx, 0
@Antek1234l
@Antek1234l 2 ай бұрын
17:55 Can this segmentation fault be prevented by adding a jmp instruction to a label above accept instruction? I think this might create infinite loop that waits for new incoming connections
@nirlichtman
@nirlichtman 2 ай бұрын
Yah, the segfault occurs since I did not exit properly by invoking the exit system call so the execution slided after finishing. I added that jump to the accept instruction in the Github code, that would make it wait for more connections
@Antek1234l
@Antek1234l 2 ай бұрын
Okay, thank you!
@PublyoRaymundo
@PublyoRaymundo 3 ай бұрын
not really a web server, but a starting point on how to handle sockets.
@vladislavknyazkov1962
@vladislavknyazkov1962 3 ай бұрын
Next video: writing minimalist web server in x86 machine code
@idjles
@idjles 3 ай бұрын
6502
@user-ed1nw6vr8n
@user-ed1nw6vr8n 3 ай бұрын
assembly is literally a fancy machine code in english
@joshnjoshgaming
@joshnjoshgaming 3 ай бұрын
LET'S FUCKLIGN GOOO!!!!! YES YES YES YES YES YES YES YES YES YES YES YES YES YES!!! YES!!
@jengstrm2
@jengstrm2 3 ай бұрын
I'd love to see the benchmarks. Is it faster than NGINX?
@interrrp_with_three_rs
@interrrp_with_three_rs 3 ай бұрын
nope, nginx utilizes multiprocessing, this one does not
@TheUnkow
@TheUnkow 2 ай бұрын
Just use another app to route the incoming requests to different ports and have each core run a process of this server listening on each of those ports. Even that can be done via round robin in a fresh assembly project. As the code is so simple and has no security checks (which is ok when you don't serve client data), it should be blazing fast. You can even add a counter to save visits by IP in case you are DDoSed, you will still get most basic attacks off your back with a few more lines.
@interrrp_with_three_rs
@interrrp_with_three_rs 2 ай бұрын
@@TheUnkow so a reverse proxy? 😃
@churchers
@churchers 2 ай бұрын
@@interrrp_with_three_rs this is almost certainly faster than nginx for what it does - return a single file. Just the code in nginx to handle processing the request content, parse the url, map to a local file and related security checks/etc would be orders of magnitude more instructions than this entire program.
@amitmalaker5445
@amitmalaker5445 3 ай бұрын
video request: make video on how to run a fasm macro in parallel with threading or with a separate process.
@nirlichtman
@nirlichtman 3 ай бұрын
You mean a video explaining how to call assembly code from C ?
@amitmalaker5445
@amitmalaker5445 3 ай бұрын
no like using thread and epoll using fasm @@nirlichtman
@mattmmilli8287
@mattmmilli8287 2 ай бұрын
🤯
@Vimposh
@Vimposh 3 ай бұрын
Next episode: making html templates
@WiihawkPL
@WiihawkPL 3 ай бұрын
>linux assembly tutorial >uses windows
@micosair
@micosair 3 ай бұрын
In before RollerCoaster Tycoon 3D video in assembly....
@CryptAmine
@CryptAmine 3 ай бұрын
Why don't we have the same man page for " socket ", and there is no manual entry for "syscall" , I'm on Linux 6.7.4-arch
@PatrikGafvert
@PatrikGafvert 3 ай бұрын
If you man -k socket You see that it's in manual 7. So man 7 socket
@disdroid
@disdroid 2 ай бұрын
fasm😍
@coding_pepper
@coding_pepper 3 ай бұрын
you are insaine
@EndreSzasz
@EndreSzasz 3 ай бұрын
The lack of fclose is disturbing
@nirlichtman
@nirlichtman 3 ай бұрын
Skipped cleanup/error handling in the video to keep it short (also added a disclaimer in the video around the middle). In the Github repo, I added calls to close
@diandradeeke
@diandradeeke 2 ай бұрын
Your videos are always so good but you are talking very fast and its difficult to keep track
@nirlichtman
@nirlichtman 2 ай бұрын
Thanks for the feedback, will take that into consideration 👍
@Matt-ht8mc
@Matt-ht8mc 12 күн бұрын
you can change the speed of the vid at will
@ango_coding
@ango_coding 3 ай бұрын
What about for windows ?
@dfoxg
@dfoxg 3 ай бұрын
That would really be interesting to see the differences in this low level!
@nirlichtman
@nirlichtman 3 ай бұрын
Winsock is also planned :)
@rian0xFFF
@rian0xFFF 3 ай бұрын
Is this web assembly
@jackkendall6420
@jackkendall6420 3 ай бұрын
lmao
@mattmmilli8287
@mattmmilli8287 2 ай бұрын
someone make primeagen watch this 😂 dang
@azabass
@azabass 3 ай бұрын
If youre just using a C Libraries through syscalls anyway, why write it in asm at all?
@thisisnotok2100
@thisisnotok2100 3 ай бұрын
I had this same thought, but the bottom line is, it's for fun. If he wasn't using the syscalls or c libs, he'd have to write his own OS to do it.
@brahimchaouchi
@brahimchaouchi 3 ай бұрын
syscalls are 'plugs' in the kernel. The simplest way to discover the syscall 'names' is to backtrace c 'wrappers' and voila
@oraz.
@oraz. 3 ай бұрын
He's not really using c libraries. The c code is a trick to get constants out of the header files.
@illegalsmirf
@illegalsmirf 3 ай бұрын
On LInux? I see a Windows task bar at the bottom.
@gerardjensenolmos7862
@gerardjensenolmos7862 3 ай бұрын
He's accessing to a Linux system through Windows
@user-ed1nw6vr8n
@user-ed1nw6vr8n 3 ай бұрын
he is using wsl 2
@mettle_x
@mettle_x 3 ай бұрын
That's too high-level. Consider using op-codes and binary-encoded machine instructions that work without an OS, i.e. Web Server in the BIOS.
@iwota
@iwota 3 ай бұрын
> he uses windows
@markmanning2921
@markmanning2921 3 ай бұрын
My biggest critism is tht NONE of the code you are laying down is commented. There is NO such thing as "self documenting code" especially not assembler which is what I write a significant amount of my Linux code in.
@nirlichtman
@nirlichtman 3 ай бұрын
"Code never lies, comments sometimes do"
@Crux161
@Crux161 2 ай бұрын
Comments are fairly pointless unless they help *you* remember something for yourself. If you can’t read the code then umm…yeah. 😬
@markmanning2921
@markmanning2921 2 ай бұрын
@@Crux161Comments are not only there for you, they are there for the poor shmuck that has to deep dive into your code maybe even years later. I have built my entire career around having to fix or maintain code written decades ago that has been hacked on repeatedly making the entire thing an unmaintainable cluster bleep (think of "a patchy web server" becoming the "apache web server" for example). Comments explain what you are thinking while you code, the logic behind the inner workings. I have also always said that if you have thought about your code long enough to explain it to someone else then you have thought about it long enough to code it otherwise you have not. NO code is self documenting, specially when you have if/and/but loops nested to the umpteenth level. Every block is an inlined, anonymous function. If people broke blocks out into sub functions it would move towards self documening but it NEVER truly gets there.
Making Snake Boot Sector Game in Assembly (x86)
19:52
Nir Lichtman
Рет қаралды 9 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 318 М.
Be kind🤝
00:22
ISSEI / いっせい
Рет қаралды 6 МЛН
CAN YOU HELP ME? (ROAD TO 100 MLN!) #shorts
00:26
PANDA BOI
Рет қаралды 27 МЛН
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 941 М.
Sean Baxter: Safe C++
1:28:00
Tristan Brindle
Рет қаралды 4,7 М.
Making Minimalist HTTPS Server in C on Linux
16:11
Nir Lichtman
Рет қаралды 15 М.
Building MS-DOS 4.00 on FreeDOS
24:48
FreeDOS
Рет қаралды 25 М.
What Happens When Booting Linux with Low Memory
5:11
Nir Lichtman
Рет қаралды 60 М.
Signals. I spent 2 years to understand this part.
21:24
kimylamp
Рет қаралды 139 М.
Making Simple Graphical Linux Distro from Scratch
17:19
Nir Lichtman
Рет қаралды 48 М.
Making Minimalist Chat Server in C on Linux
14:28
Nir Lichtman
Рет қаралды 38 М.
Эффект Карбонаро и бумажный телефон
1:01
История одного вокалиста
Рет қаралды 2,5 МЛН
Apple. 10 Интересных Фактов
24:26
Dameoz
Рет қаралды 120 М.
What’s your charging level??
0:14
Татьяна Дука
Рет қаралды 6 МЛН
Готовый миниПК от Intel (но от китайцев)
36:25
Ремонтяш
Рет қаралды 447 М.
Чем отличается OLED от AMOLED?
0:43
Не шарю!
Рет қаралды 678 М.