Тёмный

Making Minimalist Web Server in Assembly on Linux (x64) 

Nir Lichtman
Подписаться 44 тыс.
Просмотров 35 тыс.
50% 1

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...

Наука

Опубликовано:

 

16 фев 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 107   
@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 Месяц назад
@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 3 месяца назад
This looks like sorcery, but sorcery is actually all the levels of abstractions uppon which we are used to develop. Very nice content
@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 :)
@Crux161
@Crux161 3 месяца назад
I love how he shows what documentation to reference, and people still call it sorcery 😂
@Mauriciohse
@Mauriciohse 3 месяца назад
Great video man, always so cool to see how things happen under the hood. Ty!
@anthonygayflor
@anthonygayflor 2 месяца назад
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.
@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 :)
@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.
@ItsCOMMANDer_
@ItsCOMMANDer_ 4 месяца назад
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.
@honeymak
@honeymak 3 месяца назад
thx for all the heavy lifting of the pre-knowledge for this video to be made
@jsaenzMusic
@jsaenzMusic 3 месяца назад
Bro......THIS is what I'm talking about! Thank you for this content!!!!
@user-gh4lv2ub2j
@user-gh4lv2ub2j 4 месяца назад
Thank you for your service sir.
@twobob
@twobob 3 месяца назад
very nice as always. thanks for the repo
@forevervoyaging
@forevervoyaging 3 месяца назад
While this is pure wizardry, your explanation is crystal clear and makes everything easy to follow. Outstanding work!
@plato4ek
@plato4ek 3 месяца назад
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 3 месяца назад
Thanks! added :)
@milk-it
@milk-it 3 месяца назад
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 3 месяца назад
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.
@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.
@lightyr
@lightyr 20 дней назад
סרטון מעולה, הסברת את זה ממש טוב
@nirlichtman
@nirlichtman 20 дней назад
תודה!
@dj.yacine
@dj.yacine 3 месяца назад
Always creative
@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 :)
@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
@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"
@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 :)
@durimmiziraj4815
@durimmiziraj4815 3 месяца назад
Great channel!
@madwilliamflint
@madwilliamflint 4 месяца назад
I love it!
@savire.ergheiz
@savire.ergheiz 3 месяца назад
Now lets create full scaleable enterprise app 😂
@dev.rahulgurjar
@dev.rahulgurjar 3 месяца назад
Amazing 🤩
@llj0000
@llj0000 3 месяца назад
Love this stuff bro, but please do xor rdx, rdx instead of mov rdx, 0
@biohazardouszxellium
@biohazardouszxellium 2 месяца назад
Based on your experience, in which scenario would be appropriate to use. NASM/FASM/MASM/etc? Subscribed by the way!
@nirlichtman
@nirlichtman 2 месяца назад
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 2 месяца назад
@@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 2 месяца назад
@@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!
@hippie999
@hippie999 3 месяца назад
please make a video about creating a color theme for Vim 🙏
@AMith-lv2cv
@AMith-lv2cv 3 месяца назад
🔥🔥🔥🔥 wanna more and more
@kbsanders
@kbsanders 3 месяца назад
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
@elyazidful
@elyazidful 3 месяца назад
I like it !
@hidoHido-vm4en
@hidoHido-vm4en 3 месяца назад
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 ?
@PublyoRaymundo
@PublyoRaymundo 3 месяца назад
not really a web server, but a starting point on how to handle sockets.
@HP-gk7us
@HP-gk7us 3 месяца назад
Love! ❤
@Bobby-sm3sy
@Bobby-sm3sy 3 месяца назад
legend
@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 3 месяца назад
🤯
@Antek1234l
@Antek1234l 3 месяца назад
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 3 месяца назад
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 3 месяца назад
Okay, thank you!
@Vimposh
@Vimposh 3 месяца назад
Next episode: making html templates
@vladislavknyazkov1962
@vladislavknyazkov1962 4 месяца назад
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
@micosair
@micosair 3 месяца назад
In before RollerCoaster Tycoon 3D video in assembly....
@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 3 месяца назад
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 3 месяца назад
@@TheUnkow so a reverse proxy? 😃
@churchers
@churchers 3 месяца назад
@@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.
@joshnjoshgaming
@joshnjoshgaming 4 месяца назад
LET'S FUCKLIGN GOOO!!!!! YES YES YES YES YES YES YES YES YES YES YES YES YES YES!!! YES!!
@WiihawkPL
@WiihawkPL 3 месяца назад
>linux assembly tutorial >uses windows
@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
@diandradeeke
@diandradeeke 3 месяца назад
Your videos are always so good but you are talking very fast and its difficult to keep track
@nirlichtman
@nirlichtman 3 месяца назад
Thanks for the feedback, will take that into consideration 👍
@Matt-ht8mc
@Matt-ht8mc Месяц назад
you can change the speed of the vid at will
@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
@disdroid
@disdroid 3 месяца назад
fasm😍
@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 :)
@mattmmilli8287
@mattmmilli8287 3 месяца назад
someone make primeagen watch this 😂 dang
@coding_pepper
@coding_pepper 3 месяца назад
you are insaine
@rian0xFFF
@rian0xFFF 3 месяца назад
Is this web assembly
@jackkendall6420
@jackkendall6420 3 месяца назад
lmao
@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 3 месяца назад
Comments are fairly pointless unless they help *you* remember something for yourself. If you can’t read the code then umm…yeah. 😬
@markmanning2921
@markmanning2921 3 месяца назад
@@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
Making Simple Graphical Linux Distro from Scratch
17:19
How did they do?! 😂👀🕺 | Triple Charm #Shorts
00:16
Web in Native Assembly (Linux x86_64)
2:03:41
Просмотров 54 тыс.
unlock the lowest levels of coding
7:05
Просмотров 228 тыс.
Making Minimalist HTTPS Server in C on Linux
16:11
Просмотров 16 тыс.
Coding a Web Server in 25 Lines - Computerphile
17:49
Просмотров 322 тыс.
Become a shell wizard in ~12 mins
12:25
Просмотров 217 тыс.
What Happens When Booting Linux with Low Memory
5:11
So You Think You Know Git - FOSDEM 2024
47:00
Просмотров 987 тыс.
Why Linux is better for (most) developers!
14:59
Просмотров 462 тыс.
Signals. I spent 2 years to understand this part.
21:24
Apache vs NGINX
7:53
Просмотров 251 тыс.
Face ID iPhone 14 Pro
0:59
Просмотров 12 тыс.