CS 161 Computer Security

Size: px
Start display at page:

Download "CS 161 Computer Security"

Transcription

1 Paxson Spring 2013 CS 161 Computer Security Discussion 2 January 30, 2013 Question 1 Buffer Overflow Mitigations (10 min) Buffer overflow mitigations generally fall into two categories: (i) eliminating the cause and (ii) alleviating the damage. In lecture, we saw memory-safe languages and proofs as examples for the first category. This question is about techniques in the second category. Several requirements must be met for a buffer overflow to succeed. Each requirement listed below can be combated with a different countermeasure. With each mitigation you discuss, think about where it can be implemented common targets include the compiler and the operating system (OS). Also discuss limitations, pitfalls, and costs of each mitigation. (a) The attacker needs to overwrite the return address on the stack to change the control flow. Is it possible to prevent this from happening or at least detect when it occurs? (b) The overwritten return address must point to a valid instruction sequence. The attacker often places the malicious code to execute in the vulnerable buffer. However, the buffer address must be known to set up the jump target correctly. One way to find out this address is to observe the program in a debugger. This works because the address tends to same across multiple program runs. What could be done to make it harder to accurately find out the address of the start of the malicious code? (c) Attackers often store their malicious code in the same inside the buffer that they overflow. What mechanism could prevent the execution of the malicious code? What type of code would break with this defense in place? Solution: (a) Stack Canaries. A canary or canary word is a known value placed between the local variables and control data on the stack. Before reading the return address, code inserted by the compiler checks the canary against the known value. Since a successful buffer overflows needs to overwrite the canary before reaching the return address, and the attacker cannot predict the canary value, the canary validation will fail and stop execution prior to the jump. Page 1 of 19

2 As an example, consider the following function. void vuln() char buf[32]; gets(buf); The compiler will take this function and generate: /* This number is randomly set before each run. */ int MAGIC = rand(); void vuln() int canary = MAGIC; char buf[32]; gets(buf); if (canary!= MAGIC) HALT(); Limitations. Canaries only protect against stack smashing attacks, not against heap overflows or format string vulnerabilities. Local variables, such as function pointers and authentication flags, can still be overwritten. No protection against buffer underflows. This can be problematic in combination with the previous point. If the attack occurs before the end of the function, the canary validation does not even take place. This happens for example when an exception handler on the stack gets invoked before the function returns. A canary generated from a low-entropy pool can be predictable. In 2011 research showed that the Windows canary implementation only relied on 1 bit of entropy [3]. Cost. The canary has to be validated on each function return. The performance overhead is only a few percent since a canary is only needed in functions with local arrays. To determine whether to use the canary, Windows additionally applies heuristics (which unfortunately can also be subverted [1].) (b) Address Randomization. When the OS loader puts an executable into memory, it maps the different sections (text, data/bss, heap, stack) to fixed memory Discussion 2 Page 2 of 19 CS 161 SP 13

3 locations. In the mitigation technique called address space layout randomization (ASLR), rather than deterministically allocating the process layout, the OS randomizes the starting base of each section. This randomization makes it more difficult for an attacker to predict the addresses of jump targets. For instance, the OS might decide to start stack frames from somewhere other than the highest memory address. Limitations. Entropy reduction attacks can significantly lower the efficacy of ASLR [6]. For example, reducing factors are page alignment requirements (stack: 16 bytes, heap: 4096 bytes). Address space information disclosure techniques can force applications to leak known addresses (e.g., DLL addresses). Revealing addresses via brute-forcing can also be an effective technique when an application does not terminate, e.g., when a block that catches exceptions exists. Techniques known as heap spraying and JIT spraying [2] allow an attacker to inject code at predictable locations. Like the canary defense, ASLR also does not defend against local data manipulation. Not all applications work properly with ASLR. In Windows, some opt out via the /DYNAMICBAS linker flag [4]. Cost. The overhead incurred by ASLR is negligible. (c) Executable Space Protection. Modern CPUs include a feature to mark certain memory regions non-executable. AMD calls this feature the NX (no execute) bit and Intel the XD (execute disable) bit. The idea is to combat buffer overflows where the attacker injects own code. OpenBSD pioneered this technique in 2003 with W X (write x-or execute), which marks pages as either writable or executable, but not both at the same time. Since Service Pack 2 in 2004, Windows features data execution prevention (DEP), an executable space protection mechanism that uses the NX or XD bit to mark pages, which are intended to only contain data, as non-executable. Limitations. An attacker does not have to inject its own code. It is also possible to leverage existing instruction sequences in memory and jump to them. See part Question 2 for details. The defense mechanism disallows execution of code generated at runtime, such as during JIT compilation or self-modifying code (SMC). Discussion 2 Page 3 of 19 CS 161 SP 13

4 If code is loaded at predictable addresses, it is possible to turn non-executable into executable code, e.g., via system functions like VirtualAlloc or VirtualProtect on Windows [4]. Cost. There is no measurable overhead due to the hardware support of modern CPUs. Question 2 Arc Injection (10 min) Imagine that you are trying to exploit a buffer overflow, but you notice that none of the code you are injecting will execute for some reason. How frustrating! You still really want to run some malicious code, so what could you try instead? Hint: In a stack smashing attack, you can overwrite the return address with any address of your choosing. Solution: Rather than injection code, the main idea of arc injection is to inject data. It is a powerful technique to that bypasses numerous protection mechanisms, in particular executable space protection (Question 1c). By injecting malicious data that existing instructions later operates on, an attacker can still manipulate the execution path. For example, an attacker can overwrite the return address with a function in libc, such as system(const char* cmd) whose single argument cmd is the new program to spawn. The attacker also has to setup the arguments (i.e., the data) appropriately. Recall that function arguments are pushed in reverse order on the stack before pushing the return address. Consider the example below, where an attacker overwrites the return address with the address of system (denoted by &system) to spawn a shell. rip sfp esp &"/bin/sh" dummy &system esp &"/bin/sh" return addr &system esp buffer padding padding The first figure on the left is the stack layout before the attack. The second figure in the middle represents the state after having overflowed the buffer. Here, the return address is overwritten with &system. The value above is the location of the return address, from the perspective of system s stack frame. But since the attacker plans on spawning a shell that blocks to take evil commands (e.g., rm -rf /), this value will never be used hence any dummy value will suffice. The argument to system is the address of attacker-supplied data, in this case a pointer to the string /bin/sh. Discussion 2 Page 4 of 19 CS 161 SP 13

5 Finally, the third figure displays the stack state after transferring control to system, which happened by popping &system into the program counter (and decrementing the stack pointer). At this point, the attacker can execute commands using the shell. A more sophisticated version of arc injection is called return-oriented programming (ROP) [5]. It is based on the observations that the virtual memory space (which has the C library) offers many little code snippets, gadgets, that can be parsed as a valid sequence of instructions and end with a ret instruction. Recall that the ret instruction is equivalent to popl %eip, i.e., it writes the top of the stack into the program counter. The attacker does not even have to jump to the start of a function, any arbitrary location in the middle works as long as it terminates with a ret. Shacham et al. showed that these small gadgets can be combined to perform arbitrary computation. In our above example, a basic combination of two gadgets would involve writing the starting address of the next gadget at the value of dummy. When the first gadget finishes, the next one is loaded by executing ret. Setting up the stack is very tricky to get right manually, but the paper referenced above actually wrote a compiler to transform code from a language as expressive as C-like into mixture of gadgets to be pushed on the stack! Discussion 2 Page 5 of 19 CS 161 SP 13

6 Question 3 Reasoning about Memory Safety (10 min) Consider the following C code: int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) if (issafe(s[j])) s[i] = s[j]; i++; j++; else j++; return i; int issafe(char c) return ( a <= c && c <= z ) ( 0 <= c && c <= 9 ) (c == _ ); We d like to know the conditions under which sanitize is memory-safe, and then prove it. On the next page, you can find the same code again, but with blank spaces that you need to fill in (a-f). You don t need to prove the safeness of issafe. Recall our proving strategy from lecture: 1. Identify each point of memory access 2. Write down precondition it requires 3. Propagate requirement up to the beginning of the function Hint: Propagating the requirement up to the beginning of the function is more involved than in lecture. Here you need to reason about the properties that hold about the array indices after they are modified. Discussion 2 Page 6 of 19 CS 161 SP 13

7 /* (a) requires: */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) invariant: */ - if (issafe(s[j])) /* (c) invariant: */ s[i] = s[j]; i++; j++; /* (d) invariant: */ else j++; /* (e) invariant: */ /* (f) invariant: */ -- return i; Discussion 2 Page 7 of 19 CS 161 SP 13

8 Solution: Note: you might be able to develop the necessary invariants using simpler or more direct analytical approach. Here we strive to proceed very methodically using a large number of small steps, as that s the most clear and least error-prone process. Such care can become particularly important when attempting to reason about more complex code. But if you can work out proofs correctly in a more direct manner, that s fine. The bottom line is making sure you have a correct proof! Since the goal is to prove memory safety, the first step is to identify points in the code that can violate this property, and write down the preconditions for these points of interest. This step establishes what we ultimately need to prove. In this particular example, only the array accesses s[i] or s[j] can violate the memory safety property. Let s write down the preconditions for statements involving these memory accesses. /* requires: s!= NULL && 0 <= j < size (s) */ issafe(s[j]) Note that we only wrote down the condition for this particular array access, ignoring everything else in the program. Similarly, /* requires: s!= NULL && 0 <= j < size (s) && 0 <= i < size (s) */ s[i] = s[j] We wrote the above preconditions using compound relationals (like a b < c). While more succinct, those are actually harder to reason about because they involve more than one condition, and during the reasoning process we may know that part of the compound holds, but not yet be sure we have the right form for the other part. So we rewrite them in expanded form: /* requires: s!= NULL && 0 <= j && j < size (s) */ issafe(s[j])... /* requires: s!= NULL && 0 <= j && j < size (s) && 0 <= i && i < size (s) */ s[i] = s[j] Now, we need to propagate the implications of these requirements up to the function precondition. That is, given we need those preconditions to hold, what does that ultimately translate into in terms of the precondition for calling the function? When dealing with loops, this propagation step involves reasoning about code that comes after the memory accesses as well. The procedure for propagation is to walk through the code writing invariants at each point in the code. Recall that an invariant is what is guaranteed to be true of the state of variables whenever we reach that point in execution. In developing these invariants, we will establish elements of them by imposing preconditions earlier in Discussion 2 Page 8 of 19 CS 161 SP 13

9 the code s execution, ultimately up to the calling of the function itself. Doing so can take repeated passes through a set of candidate invariants, firming up each element in an invariant as we can reason it must hold, or perhaps adjusting it if we discover we didn t get it quite right the first time. How do we construct the invariants? One point of confusion is: for some invariants, isn t part of the invariant what we are trying to prove? For example, how do we know what state of variables we can guarantee to hold at point (b) in this code? We start off with a framing of what we believe the invariant will look like, marking each uncertain element with?, and then set about successively examining the invariants to determine which parts we can directly establish. Thus, we start off with parts marked does it hold?, and update those to it holds as we work through the code. Let s now walk through the code and illustrate the above process. Step 1: (a) To begin, we don t have any clear picture yet regarding the precondition for the function, so this is simply?. We will come back to this later once we have worked out what needs to be propagated. (b) The loop condition ensures j < n. This will clearly always hold at this point. Note that while the loop initialization ensures that the first time executing we have i = j = 0, that does not necessarily hold for subsequent iterations (indeed, we would not expect it to), so we don t include that fact in our draft invariant here. So for this part, for our first step we have the precondition required by the next statement, marked as uncertain, and the fact ensured by the loop condition, which is not uncertain. (c) The preceding if statement doesn t modify j, so we can include the loop condition at this point too. The rest of our candidate invariant here comes from the precondition for the assignment. (d) Here we take the invariant from above and update it to reflect that i and j have been incremented. (There s actually a subtle point here: incrementing can cause variables to overflow. Therefore, what we ve written down here won t in fact necessarily hold. We return to this point later, as an example of how we can sometimes have to fix up a candidate invariant when we discover we can t prove it.) (e) The reasoning here is similar to that for (d), except only j has been incremented. (f) At this point, we take what we can logically establish given that we know either (d) holds or (e) holds, but we don t know which one. Thus, our candidate invariant is the minimum that follows from both of them, giving us something that is true regardless of which of the if-else branches is taken. (This is why our Discussion 2 Page 9 of 19 CS 161 SP 13

10 candidate invariant for (f) doesn t make mention of constraints on i, since (e) doesn t provide any such constraints.) /* (a) requires:? */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= j? && j < size(s)? && s!= NULL? */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i? && i < size(s)? && 0 <= j? && j < size(s)? && s!= NULL? */ s[i] = s[j]; i++; j++; /* (d) Invariant: j <= n && 0 < i? && i <= size(s)? && 0 < j? && j <= size(s)? && s!= NULL? */ else j++; /* (e) Invariant: j <= n && 0 < j? && j <= size(s)? && s!= NULL? */ /* (f) Invariant: j <= n && 0 < j? && j <= size(s)? && s!= NULL? */ return i; Step 2: Right now there are a lot of? s. We can do a bit of initial simplification regarding s!= NULL?. Since the code never alters s itself, the only way to ensure that s!= NULL holds is that it s a precondition for calling the function. That gives us this simple update: Discussion 2 Page 10 of 19 CS 161 SP 13

11 /* (a) requires: s!= NULL &&? */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= j? && j < size(s)? && s!= NULL */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i? && i < size(s)? && 0 <= j? && j < size(s)? && s!= NULL */ s[i] = s[j]; i++; j++; /* (d) Invariant: j <= n && 0 < i? && i <= size(s)? && 0 < j? && j <= size(s)? && s!= NULL */ else j++; /* (e) Invariant: j <= n && 0 < j? && j <= size(s)? && s!= NULL */ /* (f) Invariant: j <= n && 0 < j? && j <= size(s)? && s!= NULL */ return i; That is, we added to the function s precondition, and removed the? s around the s!= NULL parts of the invariants, since given the precondition, we re now confident that those hold. Step 3: The next simplification is to observe that we often want to establish conditions like 0 <= i? or 0 < i?. The first of these follows immediately because i and j are type size_t, so we can mark those as resolved (remove the? ). Note that that observation does not quite allow us to do away with the?, because simply the fact that i is of type size_t does not guarantee that it is strictly larger than 0. Indeed, even if it was larger than zero before being incremented, it might overflow and become zero. That observation suggests that some of our original can- Discussion 2 Page 11 of 19 CS 161 SP 13

12 didate invariants had flaws (things we might not be able to prove). Accordingly, we decide to relax those invariants that have conditions like to 0 < i? to instead have 0 <= i?. These latter then can be changed to 0 <= i because of the observation that i s type is size_t. In general, this notion of making an invariant more relaxed is an important reasoning technique to keep in mind. Sometimes the immediate constraint implied by a statement is more narrow than what we need for our overall reasoning. Note that relax means make broader ; you have to ensure that relaxing the constraint has not undermined the original preconditions for memory safety. Another note: had the variables instead been of type int, then the reasoning here would have been more difficult. Indeed, we would need to resort to induction to reason about requirements that ensure that the condition holds. We will see an example of using induction below in Step 8. This leads then to: /* (a) requires: s!= NULL &&? */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= j && j < size(s)? && s!= NULL */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i && i < size(s)? && 0 <= j && j < size(s)? && s!= NULL */ s[i] = s[j]; i++; j++; /* (d) Invariant: j <= n && 0 <= i && i <= size(s)? && 0 <= j && j <= size(s)? && s!= NULL */ else j++; /* (e) Invariant: j <= n && 0 <= j && j <= size(s)? && s!= NULL */ Discussion 2 Page 12 of 19 CS 161 SP 13

13 /* (f) Invariant: j <= n && 0 <= j && j <= size(s)? && s!= NULL */ return i; Step 4: When we inspect the above, what s left are questions about the relationship between i and j to size(s). This part requires some thought. In particular, we have some candidate invariants inside the loop that want to provide conditions on i, but the candidate invariants at the top of the loop and at its bottom do not discuss i. That s going to make it hard to reason about properties of i inside the loop. So we extend the other candidate invariants to include information about i as well, by propagating the conditions we need inside the loop. This gives us: /* (a) requires: s!= NULL &&? */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= i && i < size(s)? && 0 <= j && j < size(s)? && s!= NULL */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i && i < size(s)? && 0 <= j && j < size(s)? && s!= NULL */ s[i] = s[j]; i++; j++; /* (d) Invariant: j <= n && 0 <= i && i <= size(s)? && 0 <= j && j <= size(s)? && s!= NULL */ else j++; /* (e) Invariant: j <= n && 0 <= i && i < size(s)? && 0 <= j && j <= size(s)? && s!= NULL */ Discussion 2 Page 13 of 19 CS 161 SP 13

14 /* (f) Invariant: j <= n && 0 <= i && i < size(s)? && 0 <= j && j <= size(s)? && s!= NULL */ return i; This change may strike you as obvious, and you may be wondering why we didn t include these statements about i in those other candidate invariants from the start. The reason is that initially we didn t have any particular requirements for memory safety at those points that directly needed a precondition on i. It s only as we try to establish properties on i inside the loop that we now see we have to reason about i at the loop s beginning and end. (Including i from the get-go would certainly be a reasonable short-cut to take, as long as you re always careful about verifying all of the steps in your reasoning.) Step 5: Now we get to the crux of it. In (b), we have an invariant that we want to know always holds when beginning a new loop iteration. To repeat it: (b) Invariant: j < n && 0 <= i && i < size(s)? && 0 <= j && j < size(s)? && s!= NULL */ How can we establish that the? will hold? For i, it s not clear how to proceed, but we note that we have some additional information already established about j, namely j < n (first clause in the invariant). So if we happen to have n <= size(s) then it logically follows that j < size(s). Here we can inspect the code and note that n never changes. Thus, if we d like n <= size(s), that will need to be a precondition for calling the function. This gives us: /* (a) requires: s!= NULL && n <= size(s) &&? */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= i && i < size(s)? && 0 <= j && j < size(s) && s!= NULL */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i && i < size(s)? Discussion 2 Page 14 of 19 CS 161 SP 13

15 s[i] = s[j]; i++; j++; && 0 <= j && j < size(s) && s!= NULL */ /* (d) Invariant: j <= n && 0 <= i && i <= size(s)? else j++; /* (e) Invariant: j <= n && 0 <= i && i < size(s)? /* (f) Invariant: j <= n && 0 <= i && i < size(s)? return i; Step 6: All that s left is that pesky i < size(s)?. Here we need to bring a bit of reasoning to the table: why do we think it ll be the case that i never exceeds size(s)? Well, because it looks like i never exceeds j, and we know (now) that j never exceeds size(s). So we add to our candidate invariants the notion that i never exceeds j, which so far isn t proven: /* (a) requires: s!= NULL && n <= size(s) &&? */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= i && i < size(s)? && i <= j? && 0 <= j && j < size(s) && s!= NULL */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i && i < size(s)? && i <= j? && 0 <= j && j < size(s) && s!= NULL */ Discussion 2 Page 15 of 19 CS 161 SP 13

16 s[i] = s[j]; i++; j++; /* (d) Invariant: j <= n && 0 <= i && i <= size(s)? && i <= j? else j++; /* (e) Invariant: j <= n && 0 <= i && i < size(s)? && i <= j? /* (f) Invariant: j <= n && 0 <= i && i < size(s)? && i <= j? return i; Step 7: At this point, it s helpful to review some of the internal logic for this new condition. Let s assume for the moment that (b) has been fully established. Then (c) follows immediately, because there are no changes to i or j at the intervening step. (d) also follows immediately, since both i and j are changed by the same amount. (e) is trickier. j has increased, but i hasn t. Normally we might think well surely then if we had i <= j going into that increment, we will have it after doing the increment of j. But here we have to consider overflow, always a subtle part of reasoning about code. The key insight is that for j to overflow, it must have been equal to the largest expressible unsigned value just prior to the overflow. However, another part of (b) (which remember we re assuming for now has been fully established) tells us j < size(s). Since the size of a memory region can t exceed what s expressible in a size_t variable, that condition ensures that j is less than the largest expressible unsigned value. Therefore, overflow can t occur; and therefore, we will have i <= j at (e) if (b) has been fully established. Given that reasoning for (d) and (e), we know we then also have it at (f). Step 8: Almost done! Okay, how do we establish that i <= j indeed holds at (b)? When reasoning about invariants at the beginning of loops, we can need to employ induction. The base case is the first entry into the loop. Here, we can use the loop s initialization, which is that both i and j are 0. For that, we have i <= j so far, so good. The inductive step has two parts. First, we need to show that if we assume that the Discussion 2 Page 16 of 19 CS 161 SP 13

17 invariant at the beginning of the loop holds, then given that we can show that the invariant at the end of the loop (f) holds. It should be straightforward for you to confirm that this is indeed the case. Second, we need to show that if we assume the invariant at the end of the loop plus the loop condition, then we can establish that the invariant at the beginning of the loop holds. That is, we assume both: /* (f) Invariant: j <= n && 0 <= i && i < size(s) && i <= j and j < n. Again, it should be clear upon inspection (including the precondition that n <= size(s)) that these two when combined indeed give us: /* (b) Invariant: j < n && 0 <= i && i < size(s) && i <= j && 0 <= j && j < size(s) && s!= NULL */ That completes the reasoning. We ve established by induction that i <= j holds in (b), and from that and j < size(s) we have also established i < size(s). So we don t need any more preconditions for the function, and the final answer is: /* (a) requires: s!= NULL && n <= size(s) */ int sanitize(char s[], size_t n) size_t i = 0, j = 0; while (j < n) /* (b) Invariant: j < n && 0 <= i && i < size(s) && i <= j && 0 <= j && j < size(s) && s!= NULL */ if (issafe(s[j])) /* (c) Invariant: j < n && 0 <= i && i < size(s) && i <= j && 0 <= j && j < size(s) && s!= NULL */ s[i] = s[j]; i++; j++; /* (d) Invariant: j <= n && 0 <= i && i <= size(s) && i <= j else j++; /* (e) Invariant: j <= n && 0 <= i && i < size(s) && i <= j Discussion 2 Page 17 of 19 CS 161 SP 13

18 Phew! /* (f) Invariant: j <= n && 0 <= i && i < size(s) && i <= j return i; We can summarize the overall reasoning strategy using the following template, which is elaborated a bit from the one presented in lecture: (1) Identify any memory accesses that could have safety issues. (2) Write down preconditions for these. (3.1) Write down candidate invariants that will satisfy these preconditions. (3.2) Repeatedly identify any elements of those invariants that you can directly reason about and mark them as no longer uncertain. This may involve adding preconditions to the function. (3.3) For what remains, determine what sort of constraints one might add to the candidate invariants to enable proving the missing pieces, and also possibly what conditions to relax (make broader). This may enable going back to 3.2. (3.4) Use induction to indirectly reason about remaining elements. From here, one can go to 3.2 or 3.3. (4) Once you ve resolved all of the candidate invariants, you re done. A final note: do not hesitate to ask for help! Our office hours exist to help you. Please visit us if you have any questions or doubts about the material. Discussion 2 Page 18 of 19 CS 161 SP 13

19 References [1] [2] Dionysus Blazakis. Interpreter Exploitation: Pointer Inference and JIT Spraying. February [3] Matthew j00ru Jurczyk and Gynvael Coldwind. Exploiting the otherwise nonexploitable. January [4] Matt Miller. On the effectiveness of DEP and ASLR. srd/archive/2010/12/08/on-the-effectiveness-of-dep-and-aslr.aspx, December [5] Hovav Shacham. The geometry of innocent flesh on the bone: return-into-libc without function calls (on the x86). In Proceedings of the 14th ACM conference on Computer and communications security, CCS 07, pages , New York, NY, USA, ACM. [6] Hovav Shacham, Matthew Page, Ben Pfaff, Eu-Jin Goh, Nagendra Modadugu, and Dan Boneh. On the Effectiveness of Address-Space Randomization. In Proceedings of the 11th ACM conference on Computer and communications security, CCS 04, pages , New York, NY, USA, ACM. Discussion 2 Page 19 of 19 CS 161 SP 13

CS 161 Computer Security

CS 161 Computer Security Paxson Spring 2011 CS 161 Computer Security Discussion 1 January 26, 2011 Question 1 Buffer Overflow Mitigations Buffer overflow mitigations generally fall into two categories: (i) eliminating the cause

More information

CS 161 Computer Security

CS 161 Computer Security Paxson Spring 2017 CS 161 Computer Security Discussion 2 Question 1 Software Vulnerabilities (15 min) For the following code, assume an attacker can control the value of basket passed into eval basket.

More information

Memory Safety (cont d) Software Security

Memory Safety (cont d) Software Security Memory Safety (cont d) Software Security CS 161: Computer Security Prof. Raluca Ada Popa January 17, 2016 Some slides credit to David Wagner and Nick Weaver Announcements Discussion sections and office

More information

Software Security: Buffer Overflow Defenses

Software Security: Buffer Overflow Defenses CSE 484 / CSE M 584: Computer Security and Privacy Software Security: Buffer Overflow Defenses Fall 2017 Franziska (Franzi) Roesner franzi@cs.washington.edu Thanks to Dan Boneh, Dieter Gollmann, Dan Halperin,

More information

Software Security: Buffer Overflow Attacks

Software Security: Buffer Overflow Attacks CSE 484 / CSE M 584: Computer Security and Privacy Software Security: Buffer Overflow Attacks (continued) Autumn 2018 Tadayoshi (Yoshi) Kohno yoshi@cs.washington.edu Thanks to Dan Boneh, Dieter Gollmann,

More information

This time. Defenses and other memory safety vulnerabilities. Everything you ve always wanted to know about gdb but were too afraid to ask

This time. Defenses and other memory safety vulnerabilities. Everything you ve always wanted to know about gdb but were too afraid to ask This time We will continue Buffer overflows By looking at Overflow Defenses and other memory safety vulnerabilities Everything you ve always wanted to know about gdb but were too afraid to ask Overflow

More information

CSE 127: Computer Security Control Flow Hijacking. Kirill Levchenko

CSE 127: Computer Security Control Flow Hijacking. Kirill Levchenko CSE 127: Computer Security Control Flow Hijacking Kirill Levchenko October 17, 2017 Control Flow Hijacking Defenses Avoid unsafe functions Stack canary Separate control stack Address Space Layout Randomization

More information

Beyond Stack Smashing: Recent Advances in Exploiting. Jonathan Pincus(MSR) and Brandon Baker (MS)

Beyond Stack Smashing: Recent Advances in Exploiting. Jonathan Pincus(MSR) and Brandon Baker (MS) Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns Jonathan Pincus(MSR) and Brandon Baker (MS) Buffer Overflows and How they Occur Buffer is a contiguous segment of memory of a fixed

More information

CS 161 Computer Security. Week of January 22, 2018: GDB and x86 assembly

CS 161 Computer Security. Week of January 22, 2018: GDB and x86 assembly Raluca Popa Spring 2018 CS 161 Computer Security Discussion 1 Week of January 22, 2018: GDB and x86 assembly Objective: Studying memory vulnerabilities requires being able to read assembly and step through

More information

Software Vulnerabilities August 31, 2011 / CS261 Computer Security

Software Vulnerabilities August 31, 2011 / CS261 Computer Security Software Vulnerabilities August 31, 2011 / CS261 Computer Security Software Vulnerabilities...1 Review paper discussion...2 Trampolining...2 Heap smashing...2 malloc/free...2 Double freeing...4 Defenses...5

More information

Software Security: Buffer Overflow Attacks (continued)

Software Security: Buffer Overflow Attacks (continued) CSE 484 / CSE M 584: Computer Security and Privacy Software Security: Buffer Overflow Attacks (continued) Spring 2015 Franziska (Franzi) Roesner franzi@cs.washington.edu Thanks to Dan Boneh, Dieter Gollmann,

More information

CSE 127: Computer Security. Memory Integrity. Kirill Levchenko

CSE 127: Computer Security. Memory Integrity. Kirill Levchenko CSE 127: Computer Security Memory Integrity Kirill Levchenko November 18, 2014 Stack Buffer Overflow Stack buffer overflow: writing past end of a stackallocated buffer Also called stack smashing One of

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week 08 Lecture 38 Preventing Buffer Overflow Attacks Hello.

More information

Lecture 09 Code reuse attacks. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017

Lecture 09 Code reuse attacks. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Lecture 09 Code reuse attacks Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Last time No good reason for stack/heap/static data to be executable No good reason for code to be writable

More information

Inline Reference Monitoring Techniques

Inline Reference Monitoring Techniques Inline Reference Monitoring Techniques In the last lecture, we started talking about Inline Reference Monitors. The idea is that the policy enforcement code runs with the same address space as the code

More information

Return-orientated Programming

Return-orientated Programming Return-orientated Programming or The Geometry of Innocent Flesh on the Bone: Return-into-libc without Function Calls (on the x86) Hovav Shacham, CCS '07 Return-Oriented oriented Programming programming

More information

Advanced Buffer Overflow

Advanced Buffer Overflow Pattern Recognition and Applications Lab Advanced Buffer Overflow Ing. Davide Maiorca, Ph.D. davide.maiorca@diee.unica.it Computer Security A.Y. 2016/2017 Department of Electrical and Electronic Engineering

More information

Lecture 4 September Required reading materials for this class

Lecture 4 September Required reading materials for this class EECS 261: Computer Security Fall 2007 Lecture 4 September 6 Lecturer: David Wagner Scribe: DK Moon 4.1 Required reading materials for this class Beyond Stack Smashing: Recent Advances in Exploiting Buffer

More information

The Geometry of Innocent Flesh on the Bone

The Geometry of Innocent Flesh on the Bone The Geometry of Innocent Flesh on the Bone Return-into-libc without Function Calls (on the x86) Hovav Shacham hovav@cs.ucsd.edu CCS 07 Technical Background Gadget: a short instructions sequence (e.x. pop

More information

Outline. Format string attack layout. Null pointer dereference

Outline. Format string attack layout. Null pointer dereference CSci 5271 Introduction to Computer Security Day 5: Low-level defenses and counterattacks Stephen McCamant University of Minnesota, Computer Science & Engineering Null pointer dereference Format string

More information

CS 161 Computer Security

CS 161 Computer Security Paxson Spring 2011 CS 161 Computer Security Homework 1 Due: Wednesday, February 9, at 9:59pm Instructions. Submit your solution by Wednesday, February 9, at 9:59pm, in the drop box labelled CS161 in 283

More information

2 Sadeghi, Davi TU Darmstadt 2012 Secure, Trusted, and Trustworthy Computing Chapter 6: Runtime Attacks

2 Sadeghi, Davi TU Darmstadt 2012 Secure, Trusted, and Trustworthy Computing Chapter 6: Runtime Attacks Runtime attacks are major threats to today's applications Control-flow of an application is compromised at runtime Typically, runtime attacks include injection of malicious code Reasons for runtime attacks

More information

Software Security II: Memory Errors - Attacks & Defenses

Software Security II: Memory Errors - Attacks & Defenses 1 Software Security II: Memory Errors - Attacks & Defenses Chengyu Song Slides modified from Dawn Song 2 Administrivia Lab1 Writeup 3 Buffer overflow Out-of-bound memory writes (mostly sequential) Allow

More information

Modern Buffer Overflow Prevention Techniques: How they work and why they don t

Modern Buffer Overflow Prevention Techniques: How they work and why they don t Modern Buffer Overflow Prevention Techniques: How they work and why they don t Russ Osborn CS182 JT 4/13/2006 1 In the past 10 years, computer viruses have been a growing problem. In 1995, there were approximately

More information

On The Effectiveness of Address-Space Randomization. H. Shacham, M. Page, B. Pfaff, E.-J. Goh, N. Modadugu, and D. Boneh Stanford University CCS 2004

On The Effectiveness of Address-Space Randomization. H. Shacham, M. Page, B. Pfaff, E.-J. Goh, N. Modadugu, and D. Boneh Stanford University CCS 2004 On The Effectiveness of Address-Space Randomization H. Shacham, M. Page, B. Pfaff, E.-J. Goh, N. Modadugu, and D. Boneh Stanford University CCS 2004 Code-Injection Attacks Inject malicious executable code

More information

Advanced Buffer Overflow

Advanced Buffer Overflow Pattern Recognition and Applications Lab Advanced Buffer Overflow Ing. Davide Maiorca, Ph.D. davide.maiorca@diee.unica.it Computer Security A.Y. 2017/2018 Department of Electrical and Electronic Engineering

More information

Robust Shell Code Return Oriented Programming and HeapSpray. Zhiqiang Lin

Robust Shell Code Return Oriented Programming and HeapSpray. Zhiqiang Lin CS 6V81-05: System Security and Malicious Code Analysis Robust Shell Code Return Oriented Programming and HeapSpray Zhiqiang Lin Department of Computer Science University of Texas at Dallas April 16 th,

More information

kguard++: Improving the Performance of kguard with Low-latency Code Inflation

kguard++: Improving the Performance of kguard with Low-latency Code Inflation kguard++: Improving the Performance of kguard with Low-latency Code Inflation Jordan P. Hendricks Brown University Abstract In this paper, we introduce low-latency code inflation for kguard, a GCC plugin

More information

CSE 509: Computer Security

CSE 509: Computer Security CSE 509: Computer Security Date: 2.16.2009 BUFFER OVERFLOWS: input data Server running a daemon Attacker Code The attacker sends data to the daemon process running at the server side and could thus trigger

More information

Bypassing Browser Memory Protections

Bypassing Browser Memory Protections Bypassing Browser Memory Protections Network Security Instructor: Dr. Shishir Nagaraja September 10, 2011. 1 Introduction to the topic A number of memory protection mechanisms like GS, SafeSEH, DEP and

More information

CSE 565 Computer Security Fall 2018

CSE 565 Computer Security Fall 2018 CSE 565 Computer Security Fall 2018 Lecture 14: Software Security Department of Computer Science and Engineering University at Buffalo 1 Software Security Exploiting software vulnerabilities is paramount

More information

20: Exploits and Containment

20: Exploits and Containment 20: Exploits and Containment Mark Handley Andrea Bittau What is an exploit? Programs contain bugs. These bugs could have security implications (vulnerabilities) An exploit is a tool which exploits a vulnerability

More information

Outline. Memory Exploit

Outline. Memory Exploit Outline CS 6V81-05: System Security and Malicious Code Analysis Robust Shell Code Return Oriented Programming and HeapSpray Zhiqiang Lin Department of Computer Science University of Texas at Dallas April

More information

CSE 127 Computer Security

CSE 127 Computer Security CSE 127 Computer Security Stefan Savage, Fall 2018, Lecture 4 Low Level Software Security II: Format Strings, Shellcode, & Stack Protection Review Function arguments and local variables are stored on the

More information

Outline. Heap meta-data. Non-control data overwrite

Outline. Heap meta-data. Non-control data overwrite Outline CSci 5271 Introduction to Computer Security Day 5: Low-level defenses and counterattacks Stephen McCamant University of Minnesota, Computer Science & Engineering Non-control data overwrite Heap

More information

ECS 153 Discussion Section. April 6, 2015

ECS 153 Discussion Section. April 6, 2015 ECS 153 Discussion Section April 6, 2015 1 What We ll Cover Goal: To discuss buffer overflows in detail Stack- based buffer overflows Smashing the stack : execution from the stack ARC (or return- to- libc)

More information

Software Security: Buffer Overflow Defenses and Miscellaneous

Software Security: Buffer Overflow Defenses and Miscellaneous CSE 484 / CSE M 584: Computer Security and Privacy Software Security: Buffer Overflow Defenses and Miscellaneous Spring 2017 Franziska (Franzi) Roesner franzi@cs.washington.edu Thanks to Dan Boneh, Dieter

More information

Is Exploitation Over? Bypassing Memory Protections in Windows 7

Is Exploitation Over? Bypassing Memory Protections in Windows 7 Is Exploitation Over? Bypassing Memory Protections in Windows 7 Alexander Sotirov alex@sotirov.net About me Exploit development since 1999 Published research into reliable exploitation techniques: Heap

More information

CSE 127 Computer Security

CSE 127 Computer Security CSE 127 Computer Security Stefan Savage, Spring 2018, Lecture 4 Low Level Software Security II: Format Strings, Shellcode, & Stack Protection Review Function arguments and local variables are stored on

More information

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Program Vulnerabilities Professor Trent Jaeger 1 1 Programming Why do we write programs? Function What functions do we enable via our programs?

More information

Q: Exploit Hardening Made Easy

Q: Exploit Hardening Made Easy Q: Exploit Hardening Made Easy E.J. Schwartz, T. Avgerinos, and D. Brumley. In Proc. USENIX Security Symposium, 2011. CS 6301-002: Language-based Security Dr. Kevin Hamlen Attacker s Dilemma Problem Scenario

More information

CSE 127 Computer Security

CSE 127 Computer Security CSE 127 Computer Security Alex Gantman, Spring 2018, Lecture 4 Low Level Software Security II: Format Strings, Shellcode, & Stack Protection Review Function arguments and local variables are stored on

More information

Stack Vulnerabilities. CS4379/5375 System Security Assurance Dr. Jaime C. Acosta

Stack Vulnerabilities. CS4379/5375 System Security Assurance Dr. Jaime C. Acosta 1 Stack Vulnerabilities CS4379/5375 System Security Assurance Dr. Jaime C. Acosta Part 1 2 3 An Old, yet Still Valid Vulnerability Buffer/Stack Overflow ESP Unknown Data (unused) Unknown Data (unused)

More information

Countermeasures in Modern Operating Systems. Yves Younan, Vulnerability Research Team (VRT)

Countermeasures in Modern Operating Systems. Yves Younan, Vulnerability Research Team (VRT) Countermeasures in Modern Operating Systems Yves Younan, Vulnerability Research Team (VRT) Introduction Programs in C/C++: memory error vulnerabilities Countermeasures (mitigations): make exploitation

More information

Inject malicious code Call any library functions Modify the original code

Inject malicious code Call any library functions Modify the original code Inject malicious code Call any library functions Modify the original code 2 Sadeghi, Davi TU Darmstadt 2012 Secure, Trusted, and Trustworthy Computing Chapter 6: Runtime Attacks 2 3 Sadeghi, Davi TU Darmstadt

More information

Lecture 08 Control-flow Hijacking Defenses

Lecture 08 Control-flow Hijacking Defenses Lecture 08 Control-flow Hijacking Defenses Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Slides adapted from Miller, Bailey, and Brumley Control Flow Hijack: Always control + computation

More information

Module: Return-oriented Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Module: Return-oriented Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Return-oriented Programming Professor Trent Jaeger 1 Anatomy of Control-Flow Exploits 2 Anatomy of Control-Flow Exploits Two steps in control-flow

More information

Buffer overflow prevention, and other attacks

Buffer overflow prevention, and other attacks Buffer prevention, and other attacks Comp Sci 3600 Security Outline 1 2 Two approaches to buffer defense Aim to harden programs to resist attacks in new programs Run time Aim to detect and abort attacks

More information

Buffer overflow background

Buffer overflow background and heap buffer background Comp Sci 3600 Security Heap Outline and heap buffer Heap 1 and heap 2 3 buffer 4 5 Heap Outline and heap buffer Heap 1 and heap 2 3 buffer 4 5 Heap Address Space and heap buffer

More information

Module: Return-oriented Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Module: Return-oriented Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Return-oriented Programming Professor Trent Jaeger 1 1 Anatomy of Control-Flow Exploits Two steps in control-flow exploitation First -- attacker

More information

CMPSC 497 Buffer Overflow Vulnerabilities

CMPSC 497 Buffer Overflow Vulnerabilities Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA CMPSC 497 Buffer Overflow

More information

CSCE 548 Building Secure Software Buffer Overflow. Professor Lisa Luo Spring 2018

CSCE 548 Building Secure Software Buffer Overflow. Professor Lisa Luo Spring 2018 CSCE 548 Building Secure Software Buffer Overflow Professor Lisa Luo Spring 2018 Previous Class Virus vs. Worm vs. Trojan & Drive-by download Botnet & Rootkit Malware detection Scanner Polymorphic malware

More information

Exploits and gdb. Tutorial 5

Exploits and gdb. Tutorial 5 Exploits and gdb Tutorial 5 Exploits and gdb 1. Buffer Vulnerabilities 2. Code Injection 3. Integer Attacks 4. Advanced Exploitation 5. GNU Debugger (gdb) Buffer Vulnerabilities Basic Idea Overflow or

More information

Exercise 6: Buffer Overflow and return-into-libc Attacks

Exercise 6: Buffer Overflow and return-into-libc Attacks Technische Universität Darmstadt Fachbereich Informatik System Security Lab Prof. Dr.-Ing. Ahmad-Reza Sadeghi M.Sc. David Gens Exercise 6: Buffer Overflow and return-into-libc Attacks Course Secure, Trusted

More information

Lecture 1: Buffer Overflows

Lecture 1: Buffer Overflows CS5431 Computer Security Practicum Spring 2017 January 27, 2017 1 Conficker Lecture 1: Buffer Overflows Instructor: Eleanor Birrell In November 2008, a new piece of malware was observed in the wild. This

More information

CSE 361S Intro to Systems Software Lab Assignment #4

CSE 361S Intro to Systems Software Lab Assignment #4 Due: Thursday, October 23, 2008. CSE 361S Intro to Systems Software Lab Assignment #4 In this lab, you will mount a buffer overflow attack on your own program. As stated in class, we do not condone using

More information

1 Dynamic Memory continued: Memory Leaks

1 Dynamic Memory continued: Memory Leaks CS104: Data Structures and Object-Oriented Design (Fall 2013) September 3, 2013: Dynamic Memory, continued; A Refresher on Recursion Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we continue

More information

CNIT 127: Exploit Development. Ch 14: Protection Mechanisms. Updated

CNIT 127: Exploit Development. Ch 14: Protection Mechanisms. Updated CNIT 127: Exploit Development Ch 14: Protection Mechanisms Updated 3-25-17 Topics Non-Executable Stack W^X (Either Writable or Executable Memory) Stack Data Protection Canaries Ideal Stack Layout AAAS:

More information

Lecture Embedded System Security A. R. Darmstadt, Runtime Attacks

Lecture Embedded System Security A. R. Darmstadt, Runtime Attacks 2 ARM stands for Advanced RISC Machine Application area: Embedded systems Mobile phones, smartphones (Apple iphone, Google Android), music players, tablets, and some netbooks Advantage: Low power consumption

More information

BUFFER OVERFLOW DEFENSES & COUNTERMEASURES

BUFFER OVERFLOW DEFENSES & COUNTERMEASURES BUFFER OVERFLOW DEFENSES & COUNTERMEASURES CMSC 414 FEB 01 2018 RECALL OUR CHALLENGES How can we make these even more difficult? Putting code into the memory (no zeroes) Finding the return address (guess

More information

Lecture Notes on Contracts

Lecture Notes on Contracts Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,

More information

Security and Privacy in Computer Systems. Lecture 5: Application Program Security

Security and Privacy in Computer Systems. Lecture 5: Application Program Security CS 645 Security and Privacy in Computer Systems Lecture 5: Application Program Security Buffer overflow exploits More effective buffer overflow attacks Preventing buffer overflow attacks Announcement Project

More information

Return-Oriented Rootkits

Return-Oriented Rootkits Return-Oriented Rootkits Ralf Hund Troopers March 10, 2010 What is Return-Oriented Programming? New emerging attack technique, pretty hyped topic Gained awareness in 2007 in Hovav Shacham s paper The Geometry

More information

Defending Computer Networks Lecture 4: Exploit Defenses. Stuart Staniford Adjunct Professor of Computer Science

Defending Computer Networks Lecture 4: Exploit Defenses. Stuart Staniford Adjunct Professor of Computer Science Defending Computer Networks Lecture 4: Exploit Defenses Stuart Staniford Adjunct Professor of Computer Science Logis;cs Course is now official Expect an email from Stephanie Meik with your PIN Need to

More information

String Oriented Programming Exploring Format String Attacks. Mathias Payer

String Oriented Programming Exploring Format String Attacks. Mathias Payer String Oriented Programming Exploring Format String Attacks Mathias Payer Motivation Additional protection mechanisms prevent many existing attack vectors Format string exploits are often overlooked Drawback:

More information

Hacking Blind BROP. Presented by: Brooke Stinnett. Article written by: Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazie`res, Dan Boneh

Hacking Blind BROP. Presented by: Brooke Stinnett. Article written by: Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazie`res, Dan Boneh Hacking Blind BROP Presented by: Brooke Stinnett Article written by: Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Mazie`res, Dan Boneh Overview Objectives Introduction to BROP ROP recap BROP key phases

More information

CS 161 Computer Security

CS 161 Computer Security Wagner Spring 2014 CS 161 Computer Security 1/27 Reasoning About Code Often functions make certain assumptions about their arguments, and it is the caller s responsibility to make sure those assumptions

More information

Buffer Overflow Attacks

Buffer Overflow Attacks Buffer Overflow Attacks 1. Smashing the Stack 2. Other Buffer Overflow Attacks 3. Work on Preventing Buffer Overflow Attacks Smashing the Stack An Evil Function void func(char* inp){ } char buffer[16];

More information

Documentation for exploit entitled nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit

Documentation for exploit entitled nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit Documentation for exploit entitled nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit about a generic way to exploit Linux targets written by Kingcope Introduction In May 2013 a security advisory was announced

More information

Midterm 1 Review. Memory Safety & Web Attacks

Midterm 1 Review. Memory Safety & Web Attacks Midterm 1 Review Memory Safety & Web Attacks What s on the midterm? Lecture material through Feb 9 Lecture notes ("Notes on..." on the course site) Section material, per "Handout w/ solutions" Concepts

More information

Lecture Notes on Memory Layout

Lecture Notes on Memory Layout Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,

More information

Code with red border means vulnerable code. Code with green border means corrected code. This program asks the user for a password with the function

Code with red border means vulnerable code. Code with green border means corrected code. This program asks the user for a password with the function 1 Code with red border means vulnerable code. Code with green border means corrected code. This program asks the user for a password with the function IsPasswordOK(), and compares it with the correct password.

More information

CMSC 414 Computer and Network Security

CMSC 414 Computer and Network Security CMSC 414 Computer and Network Security Buffer Overflows Dr. Michael Marsh August 30, 2017 Trust and Trustworthiness You read: Reflections on Trusting Trust (Ken Thompson), 1984 Smashing the Stack for Fun

More information

Is stack overflow still a problem?

Is stack overflow still a problem? Morris Worm (1998) Code Red (2001) Secure Programming Lecture 4: Memory Corruption II (Stack Overflows) David Aspinall, Informatics @ Edinburgh 31st January 2017 Memory corruption Buffer overflow remains

More information

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Program Vulnerabilities Professor Trent Jaeger 1 Programming Why do we write programs? Function What functions do we enable via our programs?

More information

Lecture 10 Code Reuse

Lecture 10 Code Reuse Lecture 10 Code Reuse Computer and Network Security 4th of December 2017 Computer Science and Engineering Department CSE Dep, ACS, UPB Lecture 10, Code Reuse 1/23 Defense Mechanisms static & dynamic analysis

More information

Secure Programming Lecture 3: Memory Corruption I (Stack Overflows)

Secure Programming Lecture 3: Memory Corruption I (Stack Overflows) Secure Programming Lecture 3: Memory Corruption I (Stack Overflows) David Aspinall, Informatics @ Edinburgh 24th January 2017 Outline Roadmap Memory corruption vulnerabilities Instant Languages and Runtimes

More information

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Module: Program Vulnerabilities. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Program Vulnerabilities Professor Trent Jaeger 1 Programming Why do we write programs? Function What functions do we enable via our programs?

More information

Analysis of MS Multiple Excel Vulnerabilities

Analysis of MS Multiple Excel Vulnerabilities Analysis of MS-07-036 Multiple Excel Vulnerabilities I. Introduction This research was conducted using the Office 2003 Excel Viewer application and the corresponding security patch for MS-07-036 - Vulnerabilities

More information

Security Workshop HTS. LSE Team. February 3rd, 2016 EPITA / 40

Security Workshop HTS. LSE Team. February 3rd, 2016 EPITA / 40 Security Workshop HTS LSE Team EPITA 2018 February 3rd, 2016 1 / 40 Introduction What is this talk about? Presentation of some basic memory corruption bugs Presentation of some simple protections Writing

More information

SoK: Eternal War in Memory

SoK: Eternal War in Memory SoK: Eternal War in Memory László Szekeres, Mathias Payer, Tao Wei, Dawn Song Presenter: Wajih 11/7/2017 Some slides are taken from original S&P presentation 1 What is SoK paper? Systematization of Knowledge

More information

Unit Testing as Hypothesis Testing

Unit Testing as Hypothesis Testing Unit Testing as Hypothesis Testing Jonathan Clark September 19, 2012 5 minutes You should test your code. Why? To find bugs. Even for seasoned programmers, bugs are an inevitable reality. Today, we ll

More information

Homework 3 CS161 Computer Security, Fall 2008 Assigned 10/07/08 Due 10/13/08

Homework 3 CS161 Computer Security, Fall 2008 Assigned 10/07/08 Due 10/13/08 Homework 3 CS161 Computer Security, Fall 2008 Assigned 10/07/08 Due 10/13/08 For your solutions you should submit a hard copy; either hand written pages stapled together or a print out of a typeset document

More information

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 I. Logic 101 In logic, a statement or proposition is a sentence that can either be true or false. A predicate is a sentence in

More information

Exploiting Stack Buffer Overflows Learning how blackhats smash the stack for fun and profit so we can prevent it

Exploiting Stack Buffer Overflows Learning how blackhats smash the stack for fun and profit so we can prevent it Exploiting Stack Buffer Overflows Learning how blackhats smash the stack for fun and profit so we can prevent it 29.11.2012 Secure Software Engineering Andreas Follner 1 Andreas Follner Graduated earlier

More information

This exam contains 7 pages (including this cover page) and 4 questions. Once we tell you to start, please check that no pages are missing.

This exam contains 7 pages (including this cover page) and 4 questions. Once we tell you to start, please check that no pages are missing. Computer Science 5271 Fall 2015 Midterm exam October 19th, 2015 Time Limit: 75 minutes, 4:00pm-5:15pm This exam contains 7 pages (including this cover page) and 4 questions. Once we tell you to start,

More information

Return-Oriented Rootkits: Bypassing Kernel Code Integrity Protection Mechanisms

Return-Oriented Rootkits: Bypassing Kernel Code Integrity Protection Mechanisms Return-Oriented Rootkits: Bypassing Kernel Code Integrity Protection Mechanisms Ralf Hund Thorsten Holz Felix C. Freiling University of Mannheim Page 1 Motivation (1) Operating systems separate system

More information

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software.

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software. Outline Morris Worm (1998) Infamous attacks Secure Programming Lecture 4: Memory Corruption II (Stack Overflows) David Aspinall, Informatics @ Edinburgh 23rd January 2014 Recap Simple overflow exploit

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

CSc 466/566. Computer Security. 20 : Operating Systems Application Security

CSc 466/566. Computer Security. 20 : Operating Systems Application Security 1/68 CSc 466/566 Computer Security 20 : Operating Systems Application Security Version: 2014/11/20 13:07:28 Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2014 Christian

More information

Software Security: Defenses

Software Security: Defenses Software Security: Defenses 1 Magic Numbers & Exploitation Exploits can often be very brittle You see this on your Project 1: Your./egg will not work on someone else s VM because the memory layout is different

More information

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents News... 1 Buffer Overflow... 1 Malloc... 6 Linked Lists... 7 Searching... 13 Inserting... 16 Removing... 19 News Good news everyone!

More information

The first Secure Programming Laboratory will be today! 3pm-6pm in Forrest Hill labs 1.B31, 1.B32.

The first Secure Programming Laboratory will be today! 3pm-6pm in Forrest Hill labs 1.B31, 1.B32. Lab session this afternoon Memory corruption attacks Secure Programming Lecture 6: Memory Corruption IV (Countermeasures) David Aspinall, Informatics @ Edinburgh 2nd February 2016 The first Secure Programming

More information

INFORMATION SECURITY - PRACTICAL ASSESSMENT - BASICS IN BUFFER EXPLOITATION

INFORMATION SECURITY - PRACTICAL ASSESSMENT - BASICS IN BUFFER EXPLOITATION INFORMATION SECURITY - PRACTICAL ASSESSMENT - BASICS IN BUFFER EXPLOITATION GRENOBLE INP ENSIMAG http://www.ensimag.fr COMPUTER SCIENCE 3RD YEAR IF-MMIS - 1ST SEMESTER, 2011 Lecturers: Fabien Duchene -

More information

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program

More information

Post exploitation techniques on OSX and Iphone. Vincenzo Iozzo

Post exploitation techniques on OSX and Iphone. Vincenzo Iozzo Post exploitation techniques on OSX and Iphone Vincenzo Iozzo vincenzo.iozzo@zynamics.com Who I am Student at Politecnico di Milano Security Consultant at Secure Network srl Reverse Engineer at zynamics

More information

Roadmap: Security in the software lifecycle. Memory corruption vulnerabilities

Roadmap: Security in the software lifecycle. Memory corruption vulnerabilities Secure Programming Lecture 3: Memory Corruption I (introduction) David Aspinall, Informatics @ Edinburgh 24th January 2019 Roadmap: Security in the software lifecycle Security is considered at different

More information

Meltdown and Spectre - understanding and mitigating the threats (Part Deux)

Meltdown and Spectre - understanding and mitigating the threats (Part Deux) Meltdown and Spectre - understanding and mitigating the threats (Part Deux) Gratuitous vulnerability logos Jake Williams @MalwareJake SANS / Rendition Infosec sans.org / rsec.us @SANSInstitute / @RenditionSec

More information

Buffer Overflows. A brief Introduction to the detection and prevention of buffer overflows for intermediate programmers.

Buffer Overflows. A brief Introduction to the detection and prevention of buffer overflows for intermediate programmers. Buffer Overflows A brief Introduction to the detection and prevention of buffer overflows for intermediate programmers. By: Brian Roberts What is a buffer overflow? In languages that deal with data structures

More information

Non-stack Based Exploitation of Buffer Overrun Vulnerabilities on Windows NT/2000/XP

Non-stack Based Exploitation of Buffer Overrun Vulnerabilities on Windows NT/2000/XP A NGSSoftware Insight Security Research Publication Non-stack Based Exploitation of Buffer Overrun Vulnerabilities on Windows NT/20/XP David Litchfield (david@ngssoftware.com) 5 th March 22 www.ngssoftware.com

More information