what ever happened to buffer overflows?

  Рет қаралды 74,132

Low Level Learning

Low Level Learning

Жыл бұрын

Keep on learning with Brilliant at brilliant.org/LowLevelLearning. Get started for free, and hurry - the first 200 people get 20% off an annual premium subscription with my URL! Thanks again Brilliant for sponsoring this video!
You may have heard the term, buffer overflow, but you may never have heard of the little bird protecting you from this evil attack. These hero's of the night are "stack canaries", and, whether you realize it or not, they've been hiding in your code for years.
In this video, we discuss what stack canaries are, what they look like, and how they protect your code from attack.
🏫 COURSES 🏫
www.udemy.com/course/c-progra...
🔥🔥🔥 SOCIALS 🔥🔥🔥
Low Level Merch!: lowlevel.store/
Follow me on Twitter: / lowleveltweets
Follow me on Twitch: / lowlevellearning
Join me on Discord!: / discord

Пікірлер: 148
@LowLevelLearning
@LowLevelLearning Жыл бұрын
GO TRY OUT BRILLIANT GOGOGOGOGOGOGO brilliant.org/LowLevelLearning
@umikaliprivate
@umikaliprivate Жыл бұрын
I know, go is a great language
@Stopinvadingmyhardware
@Stopinvadingmyhardware Жыл бұрын
where are you pimping your merch at?
@kayakMike1000
@kayakMike1000 Жыл бұрын
@@Stopinvadingmyhardware I second that.
@grantonthenet
@grantonthenet Жыл бұрын
really just hit me with the ad spot flashbang
@TheSkyline77
@TheSkyline77 Жыл бұрын
Fun fact! The "canary in the coal mine" didn't actually die. That bottle on the top of the cage? That's so that if the bird passes out, the miner can fill the cage with oxygen and the bird recovers
@Isaacrl67
@Isaacrl67 Жыл бұрын
Only after the invention of the Canary Resuscitator, but even after that they often just had tiny little square cages that did not have resuscitators on them. Mostly they were used after a mine explosion by the rescue team trying to save miners. If the canary showed signs of distress, they would pull the rescue team and the canary out, so it didn't usually die at least.
@sootikins
@sootikins Жыл бұрын
@@Isaacrl67 But the question on everyone's mind is: which is better, a dead canary or a canary with hypoxia induced brain damage??
@serzaknightcore5208
@serzaknightcore5208 Жыл бұрын
@@sootikins Well, if it can still detect carbon monoxyde...
@JustPyroYT
@JustPyroYT Жыл бұрын
I don't have birds in my code. Only bugs...
@LowLevelLearning
@LowLevelLearning Жыл бұрын
PORQUE NO LOS DOS
@alexevier
@alexevier Жыл бұрын
porque se come los bugs :(
@stavros222
@stavros222 Жыл бұрын
You know, canary eats bugs
@alexzaslavskis4623
@alexzaslavskis4623 Жыл бұрын
be aware bugs attract birds
@stapler942
@stapler942 Жыл бұрын
This thread reminds me of the incident where one of Mao's five-year plans involved eliminating Eurasian tree sparrows, which resulted in a huge increase in locusts. The lesson being, keep some of those birds around, you might need them to fight the bugs.
@PhoenixBird9000
@PhoenixBird9000 Жыл бұрын
Birds and programming absolutely mix. I am a bird. I program. Your videos are awesome. Please keep it up! Also, respect the canaries. Both kinds.
@IngwiePhoenix
@IngwiePhoenix Жыл бұрын
Chirp! =)
@PhoenixBird9000
@PhoenixBird9000 Жыл бұрын
@@IngwiePhoenix Chirp chirp! :D
@snarkyerica
@snarkyerica Жыл бұрын
CHIIIIRP
@CodingSunset
@CodingSunset Жыл бұрын
🐥🔫
@PhoenixBird9000
@PhoenixBird9000 Жыл бұрын
@@CodingSunset Not sure what you mean there.
@atdit
@atdit Жыл бұрын
RIP stack canary. He died for our sins. 😔
@roygalaasen
@roygalaasen Жыл бұрын
In the late 80’s/early 90’s I had a computer with a small executable file running at the end of the autoexec file. All it did was saying “The canary bird is alive and all is well.” Until one day it said: “The canary bird is dead.” It was an exe file that checked an internal checksum, and if it was changed, the canary was dead, and you knew that you had been infected by a computer virus.
@davidtalysson4175
@davidtalysson4175 Жыл бұрын
Brilliant ! how it works ?
@jvmgang
@jvmgang Жыл бұрын
​@@davidtalysson4175 my friend have you read the comment
@KingBowserLP
@KingBowserLP 9 ай бұрын
@@davidtalysson4175 a lot of viruses infected a computer by inserting themselves into executable files as they're run. Changing a file changes its checksum so the next time the computer starts, it sees the checksum mismatch and outputs that message.
@AJMansfield1
@AJMansfield1 Жыл бұрын
There actually are heap canaries! You just have to call `mprobe()` on the buffer after you finish any risky operation. Unfortunately since nobody actually "owns" heap memory, the compiler can't just automatically insert this check at every function return. Alternately, you can ask nicely to have the compiler try to make its best guess by calling `mcheck()` or passing `-lmcheck` when linking. You can also do one better if you use a more paranoid allocator that uses separate virtual memory pages for each allocation and flanks them with guard pages -- that way, you get an automatic hardware exception any time something even _reads_ outside each buffer's closest 4096-byte block. (That is, in fact, what a segfault is; guard pages just make segfaults happen for buffers in the middle of the heap too, not just at the end.)
@cFyugThCzvAqYaGmxRgfCKTuvHMEjQ
@cFyugThCzvAqYaGmxRgfCKTuvHMEjQ Жыл бұрын
Alternatively, you can rewrite it in Rust!
@TheCustomFHD
@TheCustomFHD Жыл бұрын
@@cFyugThCzvAqYaGmxRgfCKTuvHMEjQ Fuck Rust, Rust is the reason Devs get dumber, and move away from the Hardware. Also the reason why a browser takes 500MB ram, instead of the 50M that it should take max.
@龗
@龗 Жыл бұрын
or use AddressSanitizer
@jonshouse1
@jonshouse1 Жыл бұрын
I used to place variables with test values manually at the end of arrays for testing, these days I use "-fsanitize=address" with gcc, great feature.
@cihatkececi2310
@cihatkececi2310 Жыл бұрын
Clang and MSVC also have address sanitizer
@TheBainMeister
@TheBainMeister Жыл бұрын
Absolutely, great videos. I haven't done much C since Uni, but need to get back into it. These videos definitely help inspire me to do that, keep up the great work man!
@LowLevelLearning
@LowLevelLearning Жыл бұрын
Great to hear!
@xxxPrzybyLxxx
@xxxPrzybyLxxx Жыл бұрын
"Here we have a C code..." - there You go You have find Your first canary.
@IsaacShekelberg
@IsaacShekelberg Жыл бұрын
Tried stack based overflows for educational purposes on self written binarys and i was wondering why my arbitrary shellcode was not executed besides NX turned off. I will go and check for canarys. Thanks! UPDATE: Yes it has canary
@MrRedwires
@MrRedwires Жыл бұрын
I guess the main problem with heap memory is knowing when to check it... But I saw another comment referring to heap canaries, which is cool! There should be support for automatic checks in some of the std memory containers, e.g. after passing the .data() pointer of a std::vector Also, fun fact! Canary bytes were re-implemented on things that don't natively support them. FreeRTOS, a popular microcontroller scheduler, allows the placement of canary bytes too. It's very useful!
@JorgetePanete
@JorgetePanete Жыл бұрын
"Here I wrote some C code-" ah, I see the problem "that's vulnerable" reduntant
@reverse.engineer.
@reverse.engineer. Жыл бұрын
Some notes on canaries: - Based on idea of ‘canary in a coal mine’ - AKA Stack Cookies - Method: Random number is placed between local variables on the stack and the return address on the stack ~**Before you return from a function you check that random number and ask if it's corrupted or not. If safe return; If not *buffer may have floweth'd over* - *USUALLY* Added by compiler Canaries are a form of Mitigation because the principal falls under certain ASSUMPTIONS: //In the words of a good friend - Never make Assumptions. 1) Linear-writing buffer overflows will corrupt the canary, and that corruption will be detected before anything bad can happen. 2) It's Hard for attacker to guess the 32/64-bit random number. 3) Not possible for attacker to read the number and then write the same number back as part of the overflow. ***Assumptions ( each of these could be violated by an attacker ) --- if attacker has control of destination pointer. --- Did the implementers have adequate randomization for the 32/64-bit number? Is there a chance the attacker can guess it? --- Can the attacker read the canary? If they can read the canary then they could write back the exact value while they're doing the linear buffer overflow. (depends on information disposal) - At the end of the day canaries are a cheap, good exploit mitigation mechanism that should be enabled.
@williamdrum9899
@williamdrum9899 Жыл бұрын
Why use a random number and not just use the actual return address?
@roygalaasen
@roygalaasen Жыл бұрын
@@williamdrum9899 my guess is that a random number always will be harder to guess for an attacker trying to exploit your code?
@_modiX
@_modiX Жыл бұрын
Now I understand why Microsoft calls their nightly Edge builds canary builds.
@naturallyinterested7569
@naturallyinterested7569 Жыл бұрын
2:57 I think that's supposed to be the function epilog? (pro - before, epi - after, so after the function might have clobbered the canary)
@sergiopolarbear810
@sergiopolarbear810 Жыл бұрын
omg thank you for this. i was using ghidra for the first time today and was wondering what that fs:offset and chk stack fail were
@mateuszmyalski9005
@mateuszmyalski9005 Жыл бұрын
The heap can be protected by specifying the max size of the heap in the linker, and then creating small section of the memory at the end of the heap that has no write permission flag on
@kayakMike1000
@kayakMike1000 Жыл бұрын
Does this trigger a hard fault like IRQ 3 in arm cortex-m0+?
@jurekrasovec
@jurekrasovec Жыл бұрын
This happened to me just yesterday with "char query[1024];" and then copy/paste "memset(query, 0x00, 2048);". Too bad you didn't post this video yesterday as I had no idea what is wrong :)
@ericbwertz
@ericbwertz Жыл бұрын
That's exactly why magic numbers in your code are bad. The only constants you should ever see in your code are (perhaps) -1, 0, 1 and NULL/null/None.
@anon_y_mousse
@anon_y_mousse Жыл бұрын
@@ericbwertz Indeed, BUFSIZ or whatever user defined macro/constant would be best.
@williamdrum9899
@williamdrum9899 Жыл бұрын
Honestly I don't have a problem with magic numbers if they're powers of 2
@anon_y_mousse
@anon_y_mousse Жыл бұрын
@@williamdrum9899 Read the original post, those are both powers of two.
@ericbwertz
@ericbwertz Жыл бұрын
@@anon_y_mousse , @William Drum And murder is OK, as long as the mess is contained in a heavy-duty Hefty bag.
@macktheripper7454
@macktheripper7454 Жыл бұрын
What a great channel, subbed
@Luxcium
@Luxcium Жыл бұрын
I have no clue why I love ❤️ watching those videos I don’t even program in C or anything I am a Typical TypeScript ScriptKiddy but not the kind that copy then paste… I am no longer merely duplicating and replicating text, for I have transcended the realm of simple synonym substitution. With the power of ChatGPT-4, I now engage in a sophisticated art of textual transmutation, skillfully weaving words and phrases to forge novel compositions that retain the essence of the original, all while evading the pedestrian confines of mere copy-pasting. 😮
@williamdrum9899
@williamdrum9899 Жыл бұрын
Not sure if this counts as a canary, but this is a trick for Sega Genesis (or any Motorola 68000 CPU). The registers are all 32 bit but the addressable memory is only 24 bit, the top byte is discarded. Many times when I was first learning the language, I would dereference a pointer more than I should have. I'd know this happened when I was expecting a memory address in a register but I got something where the top byte wasn't zero. So the trick is that you can use any value greater than 0x00FFFFFF as a canary, since that's the last memory address the CPU can load from
@esquilo_atomico
@esquilo_atomico Жыл бұрын
nice video, nice channel, everything is so nice im happy under effect of the product
@huntabadday2663
@huntabadday2663 Жыл бұрын
+respect for the canary
@Luxcium
@Luxcium Жыл бұрын
Canaries also consume insects and other small invertebrates, I believe it’s why they are used to eat bugs in code… 😅
@smlgd
@smlgd Жыл бұрын
So one thing I don't understand, the canary check code is inserted by the compiler, right? But does it detect when a function is vulnerable to buffer overflow or does it do it for every function? Is it possible to force it to not check the canary on specific functions?
@CrittingOut
@CrittingOut Жыл бұрын
Funny enough, learnt about this a few months ago. Fun.
@kayakMike1000
@kayakMike1000 Жыл бұрын
Ooooo this is so cool. Stack smashing was a thing that might be related.
@williamdrum9899
@williamdrum9899 Жыл бұрын
Yep, canaries exist to block stack smashing attempts
@lt3lt3lt3
@lt3lt3lt3 Жыл бұрын
Excellent!!
@nalayak862
@nalayak862 Жыл бұрын
what's checksec stack canary meant to protect against the buffer overflow
@_AN203
@_AN203 Жыл бұрын
Press F to pay respect....
@LowLevelLearning
@LowLevelLearning Жыл бұрын
🦆🙏
@Facebook-sk2iy
@Facebook-sk2iy Жыл бұрын
well it'snt very secure format string vulns can bypass it by overwriting the stack chk fail function
@raptoress6131
@raptoress6131 Жыл бұрын
Cool, I gotta try this out
@LowLevelLearning
@LowLevelLearning Жыл бұрын
Please do!
@funtoxin
@funtoxin Жыл бұрын
01:40 😐 we all were thinking of that 😂
@klevisimeri607
@klevisimeri607 Жыл бұрын
How did you open the code in assembly.
@ChickenNugget-je8ir
@ChickenNugget-je8ir Жыл бұрын
Respect the canary
@eljuano28
@eljuano28 Жыл бұрын
Hey, my Veterans! I know you're singing it with me: "See the little birdy with the little yellow bill!..."
@heitortremor
@heitortremor Жыл бұрын
Respect
@trannusaran6164
@trannusaran6164 Жыл бұрын
me, watching this in 6502 land: "huh, interesting!"
@kayakMike1000
@kayakMike1000 Жыл бұрын
I've been there once or twice!
@williamdrum9899
@williamdrum9899 Жыл бұрын
I've been there for far too long haha. Spent a couple years trying to make a NES game but I got tired of it
@trannusaran6164
@trannusaran6164 Жыл бұрын
@@williamdrum9899 could always hop on the 2600 like me lol
@larrycarlson3088
@larrycarlson3088 Жыл бұрын
Would be cool if you could do a video on how to take info off a serial and convert it into integer values or strings. I'm finding it hard to learn.
@eightsprites
@eightsprites Жыл бұрын
Not sure what you mean by serial. But to convert string to interger or integer to string look at functions ”atoi”, ”itoa” and ”sprintf”, ”sscanf”.
@fatkhajit3293
@fatkhajit3293 Жыл бұрын
don't use atoi, it's not secure cause it can returns false values (returns 0 on invalid value but how you differentiate this case from passing the string "0" ?) use strtol and derivates like this : char *s = "7"; char *endptr; long n = strtol(s,&endptr,10); if (*endptr != 0) //error case else // n holds integer value 7 on error case endptr will be pointing among the passes string
@fatkhajit3293
@fatkhajit3293 Жыл бұрын
btw sprintf is not secure too andcan lead to buffer overflows,uses snprintf instead
@draakisback
@draakisback Жыл бұрын
I wrote a database for secrets. One of the things that I did to protect the encrypted secrets in memory was to use canary pointers. After all, if a user could dump the secret using an overflow then it isn't very secret... Turns out, that the Canary was an easy way to find the secrets in the memory space if a user was able to do a core dump. Main issue was that the canaries themselves were not random, or at least every canary was the same throughout the program (was using libsodium). Eventually found a solution for this but it was interesting that a protection feature didn't protect the program in this case.
@bradywb98
@bradywb98 Жыл бұрын
Buffer overflows being used to overwrite the return address on the stack is a commonly cited example for how a hacker can get local code execution going. However, I’m not sure why it actually matters if they’re able to overwrite the return address. The CPU’s MMU is configured by the kernel to put W/R/X permissions on memory pages… the text (code) section of a typical process should not have W permissions enabled, so trying to write in there would cause a SEGFAULT. And the data sections of the process would not have the X permission enabled, so if a hacker was able to transfer execution there, again you’d SEGFAULT. Maybe I’m missing something here because it’s a great example to show how stacks and buffers and such work, but I don’t think it enables self modifying (intentional or by hacker) as it might’ve in the past. We have memory protection these days.
@lucaspolidori
@lucaspolidori 7 ай бұрын
It’s complicated. There’s a technique called ROP that is extremely interesting. It essentially lets you run multiple chunks of code by adding them to your long buffer overflow input in a precise way. You can load registers, write strings and other values in memory and much more. Every c program also is connected to libc which has the system function. So (oversimplifying) if you call that with /bin/sh as a parameter, you add shell code to your payload (in a precise manner) and get your remote code execution. It’s really complicated, so I can’t really explain it in a short comment. It’s also super cool imo. There are simple ways to counter the canary (and other more powerful mitigations he didn’t mention) that admittedly don’t work all the time, but these vulnerabilities are still very prevalent and this guy does not fully understand what he’s talking about.
@tomaszkarwik6357
@tomaszkarwik6357 Жыл бұрын
I always thought this was called "stack cookies", but I see there is a different name
@querela92
@querela92 Жыл бұрын
Respect the canary 😮
@oj0024
@oj0024 Жыл бұрын
somehow I was expecting this to be about combinators
@cFyugThCzvAqYaGmxRgfCKTuvHMEjQ
@cFyugThCzvAqYaGmxRgfCKTuvHMEjQ Жыл бұрын
Correction: at 4:17 you meant to say least significant byte
@Yukinebi
@Yukinebi Жыл бұрын
Oh, I use rust now. So this does not apply does it?
@conradludgate
@conradludgate Жыл бұрын
Rust explicitly checks for overflowing the memory at runtime with bounds checks. If you were to read into an array more than its capacity, it would panic with an out of bounds errors. Unless you're explicitly use unsafe and get_unchecked, then it will be vulnerable to overflows again
@HiImKyle
@HiImKyle Жыл бұрын
Not me totally going "Canary Wharf in London!"
@AmCanTech
@AmCanTech Жыл бұрын
Canariiieees
@guilherme5094
@guilherme5094 Жыл бұрын
👍F for the canary.
@galihsurya5606
@galihsurya5606 Жыл бұрын
RIP for the canary, it dies after protecting us from the bug😢
@madcode-hub6901
@madcode-hub6901 Жыл бұрын
Respect the canaries 👍
@user-uu5xf5xc2b
@user-uu5xf5xc2b Жыл бұрын
if you don't bring canaries the file screams
@thedrunknmunky6571
@thedrunknmunky6571 Жыл бұрын
I'm commenting before I watch the video, trying to see if i can guess what its about. Lets see if I am right! Canaries and protecting writing out of bounds.
@meto4545
@meto4545 Жыл бұрын
3:15
@GIJOEG36
@GIJOEG36 Жыл бұрын
F for the canaries
@LowLevelLearning
@LowLevelLearning Жыл бұрын
🙏
@kayakMike1000
@kayakMike1000 Жыл бұрын
F
@jwbowen
@jwbowen Жыл бұрын
So are we getting a "Respect the canary" t-shirt soon?
@somerandomdragon558
@somerandomdragon558 Жыл бұрын
If birds are basically huge bugs, then no. My code has no birds. It has airplanes.
@muhammadyusoffjamaluddin
@muhammadyusoffjamaluddin Жыл бұрын
I thought Canary really already in programming. For example: Google Chrome Canary Edition (Crash easier than beta edition). Kinda confused when he say it's not in programming tho...
@micycle8778
@micycle8778 Жыл бұрын
3:26 you've been taking too many notes from theprimeagen
@centdemeern1
@centdemeern1 Жыл бұрын
No birds were harmed in the making of this video
@LowLevelLearning
@LowLevelLearning Жыл бұрын
false
@fotnite_
@fotnite_ Жыл бұрын
*Numerous canaries died in the making of this video.*
@poenanster5285
@poenanster5285 Жыл бұрын
"respect the canary"
@Tristan-mr3pk
@Tristan-mr3pk Жыл бұрын
Does this mean the canary ate my bugs?
@AntonioNoack
@AntonioNoack Жыл бұрын
Great video, except for the title :/ If I was looking for canaries, I probably wouldn't find this video.
@dagoberttrump9290
@dagoberttrump9290 Жыл бұрын
-f is for flag afaik
@Tferdz
@Tferdz Жыл бұрын
easy fix: rust.
@alexzaslavskis4623
@alexzaslavskis4623 Жыл бұрын
be aware bugs attract birds
@lukeonuke
@lukeonuke Жыл бұрын
w canary
@Nameorsmth
@Nameorsmth Жыл бұрын
BRID UP!!!!
@LowLevelLearning
@LowLevelLearning Жыл бұрын
🦆
@sanjai1038
@sanjai1038 Жыл бұрын
F Canary 🐤
@GamePlays_1230
@GamePlays_1230 5 ай бұрын
I'm confused here , the OS shouldn't care what happens to your process , this feature just makes no sense
@Dashpoint-lk3zf
@Dashpoint-lk3zf Жыл бұрын
TOOOKYOOOOOOO
@Scriabinfan593
@Scriabinfan593 3 ай бұрын
Disrespect the canary.
@jbray250
@jbray250 Жыл бұрын
Reply F to pay respects for canary
@kayakMike1000
@kayakMike1000 Жыл бұрын
F
@QmVuamFtaW4
@QmVuamFtaW4 Жыл бұрын
you look way different in this video.
@FaZekiller-qe3uf
@FaZekiller-qe3uf Жыл бұрын
2.
@LowLevelLearning
@LowLevelLearning Жыл бұрын
3.
@doommusic4738
@doommusic4738 Жыл бұрын
It should ne klller
@kermitdafrog8
@kermitdafrog8 Жыл бұрын
@@LowLevelLearning 4.
@vini9598
@vini9598 Жыл бұрын
1.
@LowLevelLearning
@LowLevelLearning Жыл бұрын
AYYYYYYYYYY
@ryan1696
@ryan1696 Жыл бұрын
I'm early!
@HoSza1
@HoSza1 Жыл бұрын
spare dying canaries, use rust instead.
@mcspud
@mcspud Жыл бұрын
F for canaries
@rick_er2481
@rick_er2481 Жыл бұрын
2.
malicious javascript injected into 100,000 websites
12:28
Low Level Learning
Рет қаралды 129 М.
how do hackers exploit buffers that are too small?
8:25
Low Level Learning
Рет қаралды 188 М.
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 108 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 6 МЛН
i extracted the secrets of my son's baby monitor
8:01
Low Level Learning
Рет қаралды 447 М.
Buffer Overflows: A Symphony of Exploitation
30:18
crow
Рет қаралды 67 М.
every good programmer should know how to code this data structure (its easy)
21:08
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 205 М.
how does source become code?
8:47
Low Level Learning
Рет қаралды 94 М.
how can memory safe code STOP HACKERS?
7:43
Low Level Learning
Рет қаралды 110 М.
How A Steam Bug Deleted Someone’s Entire PC
11:49
Kevin Fang
Рет қаралды 906 М.
Stack Canary
7:00
Aaron Yoo
Рет қаралды 12 М.
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1,1 МЛН
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 52 МЛН
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 33 МЛН
Ждёшь обновление IOS 18? #ios #ios18 #айоэс #apple #iphone #айфон
0:57