diff options
author | Matt Strapp <matt@mattstrapp.net> | 2022-01-11 10:18:56 -0600 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2022-01-11 10:18:56 -0600 |
commit | 6c9b79537f03115c5e2d4883fd407a6ac870bffd (patch) | |
tree | a26cecd37bb254795e8a847ca7235d5e7236ff54 /csci5271/hw1 | |
parent | finish 3606 (diff) | |
download | homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.tar homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.tar.gz homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.tar.bz2 homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.tar.lz homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.tar.xz homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.tar.zst homework-6c9b79537f03115c5e2d4883fd407a6ac870bffd.zip |
Resume and rearrange
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'csci5271/hw1')
-rwxr-xr-x | csci5271/hw1/hw1p2a.pl | 12 | ||||
-rw-r--r-- | csci5271/hw1/hw1p2b.c | 28 | ||||
-rw-r--r-- | csci5271/hw1/hw1p3.c | 25 | ||||
-rw-r--r-- | csci5271/hw1/hw1p4.c | 32 | ||||
-rw-r--r-- | csci5271/hw1/hw1writeup.md | 120 |
5 files changed, 0 insertions, 217 deletions
diff --git a/csci5271/hw1/hw1p2a.pl b/csci5271/hw1/hw1p2a.pl deleted file mode 100755 index a8bfe2e..0000000 --- a/csci5271/hw1/hw1p2a.pl +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/perl -print "Content-Type: text/html\r\n\r\n"; -print "<HTML><BODY>\n"; -($field_name, $username_to_look_for) = split(/=/, <>); -chomp $username_to_look_for; -$result = `last -1000 | grep $username_to_look_for`; -if ($result) { -print "$username_to_look_for has logged in recently.\n"; -} else { -print "$username_to_look_for has NOT logged in recently.\n"; -} -print "</BODY></HTML>\n";
\ No newline at end of file diff --git a/csci5271/hw1/hw1p2b.c b/csci5271/hw1/hw1p2b.c deleted file mode 100644 index df5ac73..0000000 --- a/csci5271/hw1/hw1p2b.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <fcntl.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <unistd.h> -void silly_function(char *pathname) { - struct stat f, we; - int rfd, wfd; - char *buf; - stat(pathname, &f); - stat("./critical", &we); - if (f.st_dev == we.st_dev && f.st_ino == we.st_ino) { - return; - } - rfd = open(pathname, O_RDONLY); - buf = malloc(f.st_size - 1); - read(rfd, buf, f.st_size - 1); - close(rfd); - stat(pathname, &f); - if (f.st_dev == we.st_dev && f.st_ino == we.st_ino) { - return; - } - wfd = open(pathname, O_WRONLY | O_TRUNC); - write(wfd, buf, f.st_size - 1); - close(wfd); - free(buf); -} - -int main() { silly_function("./not"); }
\ No newline at end of file diff --git a/csci5271/hw1/hw1p3.c b/csci5271/hw1/hw1p3.c deleted file mode 100644 index 53ecc96..0000000 --- a/csci5271/hw1/hw1p3.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void payment(char *name, double amount_cny, char *purpose, int purpose_len) -{ - double amount_usd = amount_cny / 6.466; - char memo[40]; - strcpy(memo, "Payment for: "); - memcpy(memo + strlen(memo), purpose, purpose_len); - //write_check(name, amount_usd, memo); - printf("address of amount_usd: %p\naddress of memo: %p\n", &amount_usd, memo); - printf("purpose_len: %d\n", purpose_len); - printf("amount_usd: %f\npurpose: %s\n", amount_usd, purpose); - return; -} - -int main() -{ - char name[] = "username"; - double amount_cny = 646.60; - char purpose[] = "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41"; - int purpose_len = strlen(purpose); - payment(name, amount_cny, purpose, purpose_len); - return 0; -}
\ No newline at end of file diff --git a/csci5271/hw1/hw1p4.c b/csci5271/hw1/hw1p4.c deleted file mode 100644 index 4526e43..0000000 --- a/csci5271/hw1/hw1p4.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <stdio.h> - -/* Reverse the elements from FROM to TO, inclusive */ -void reverse_range(int *a, int from, int to) -{ - unsigned int *p = &a[from]; - unsigned int *q = &a[to]; - /* Until the pointers move past each other: */ - while (!(p == q + 1 || p == q + 2)) - { - /* Swap *p with *q, without using a temporary variable */ - *p += *q; /* *p == P + Q */ - *q = *p - *q; /* *q == P + Q - Q = P */ - *p = *p - *q; /* *p == P + Q - P = Q */ - /* Advance pointers towards each other */ - p++; - q--; - } -} - -int main() -{ - int a[10] = {255, 0, -65536, 2147483647, -2147483648, - -1, 0, 1, 2, 3}; - reverse_range(a, 9, 0); - for (int i = 0; i < 10; i++) - { - printf("%d ", a[i]); - } - printf("\n"); - return 0; -}
\ No newline at end of file diff --git a/csci5271/hw1/hw1writeup.md b/csci5271/hw1/hw1writeup.md deleted file mode 100644 index 721d669..0000000 --- a/csci5271/hw1/hw1writeup.md +++ /dev/null @@ -1,120 +0,0 @@ -# Homework 1 - -## Q1 - -### Database Threat Model - -The main threat of the model is accessing the database. Any access to the server of the database is considered a threat because it can potentially be used as a vector for privilege escalation and database access. The server can be accessed either over a network that may or may not exist or directly connecting to the machine itself. - -The potential attackers would be any students or other users who potentially have access to the machine with the database. - -The most reasonable attacks would be guessing the credentials to access the database, most likely by brute forcing a password if one exists. - -Impossible threats would be from people and devices that cannot access the machine containing the database. - -### Without Network - -Without networking hardware, one major threat vector (the network) is gone. - -One way to mitigate threats is to encrypt the database and the computer containing the database with a password resistant to brute forcing if someone were to obtain the computer. If the algorithm is slow, an old computer could be even more slowed down by the decryption. - -Another way to mitigate threats is to lock the computer up when it is not being used. - -## Q2 - -### A: Perl - -After adding a name to the request, add a semicolon followed by the command. The semicolon is the shell command separator which allows it to parse new commands. - -#### Example Request Body - -```perl -'field-name=; ls' -``` - -#### Fixes (taken from <https://docstore.mik.ua/orelly/perl4/cook/ch19_06.htm>) - -One way to fix the script would be replacing the unsafe `last -1000 | grep $username_to_look_for` command with a more safe call that cannot be hijacked for arbitrary code execution. Another way would be rewriting the script to prevent the shell being run at all. - -### B: C - - - -## Q3 - -Overfilling the buffer normally causes the program to crash from stack smashing. This can be undone by finding the canary value and using it to overwrite the canary value after the buffer overflow. The CFI can be beaten by jumping to a known legal target. - -On big and little endian machines, the byte order is reversed. - -## Q4 - -### A - -#### Mistake 1: Potentially overloading the array - -If the function is called with `to` larger than outer bound of the array, there is a buffer overflow that happens. For example, running it by default with an array of size 10 with a `to` of 11 on gcc 11.1 causes it to crash because of stack smashing. - -#### Mistake 2: Negative numbers the array - -If the function is called with `from` smaller than 0 will cause the array to look at addresses before the array, potentially causing the program to segfault. - -#### Mistake 3: Swapping the to and from - -If the function is called with `from` larger than `to`, the program will segfault from accessing invalid memory addresses. - -### B: Same Signature - -```c -void reverse_range(int *a, int from, int to) { - //Not sure how to check if to is too big - if (from < 0 || to < from) - return; - for (int i = from; i < to; i++) { - int temp = a[i]; - a[i] = a[to]; - a[to] = temp; - to--; - } -} - -``` - -### C: Different Signature - -```c - void reverse_range(int *arr, int arrSize, int from, int to) { - //Program should exit if it works backwards or goes out of bounds - if (from < 0 || to >= arrSize || to < from) - return; - for (int i = from; i < to; i++) { - int temp = arr[i]; - arr[i] = arr[to]; - arr[to] = temp; - to--; - } - return; - } -``` - -The main difference is that the function needs the size of the array since it can't be found from the function itself. - -## Q5 - -### A - -Start out with the binary representation of 20, 00010100. Then shift the bits to the right and toggle bit 31. Then left shift (multiply by 2) and you get 20. -2147483668 and 2 are two numbers that give 20 when multiplied. -Also works with 1073741829 and 4. - -### B - -The easiest way at first would seems like it would be to get the largest unsigned integer, divide it by 7 and add 3 to get the overflow to 20, getting back to multiplying and you get 7. The problem is that doesn't work. You get 17. -The next thing to try is doubling the integer and adding 20 to get it to overflow twice. Thankfully `0x200000014` is cleanly divisible by 7. - -`200000014*7=20` - -### C - -```c - printf("$1%.27d spear%c%.0x %.7sion %o\n", 0, 104, 962029, "evacuate", 13023); -``` |