ucdavis-ecs189m

[RADIOACTIVE] python exploits for uc davis class ecs189m
git clone git://git.figbert.com/ucdavis-ecs189m.git
Log | Files | Refs

commit c42133d0aad10c261c764cbc1169256741b45de8
parent 3298505503c729c57ac814b9cd9f71a5442d2d00
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Wed,  8 Jan 2020 15:50:21 -0800

Standardize comment formatting

Comments previously alternated between having a space after the hashtag and not having a space after the hashtag. All comments now have spaces after the hashtag.

Diffstat:
Mlinux_and_misc/scripts/addition.py | 10+++++-----
Mlinux_and_misc/scripts/binaryaddition.py | 8++++----
Mlinux_and_misc/scripts/strcmp.py | 28++++++++++++++--------------
Mlinux_and_misc/walkthroughs/addition.md | 10+++++-----
Mlinux_and_misc/walkthroughs/binaryaddition.md | 8++++----
5 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/linux_and_misc/scripts/addition.py b/linux_and_misc/scripts/addition.py @@ -6,20 +6,20 @@ # 04/01/2020 from pwn import * -#Connecting to the server +# Connecting to the server connection = remote("twinpeaks.cs.ucdavis.edu", 30001) for i in range(0,50): - #Recieving the equation + # Recieving the equation equation = connection.recvline_contains("Question") - #Splitting the equation into the two numbers to add + # Splitting the equation into the two numbers to add numbers = [int(item.strip()) for item in ((equation.split(b":")[1]).strip()).split(b"+")] num_one = numbers[0] num_two = numbers[1] - #Adding the two numbers + # Adding the two numbers num_sum = sum(numbers) print("Equation %d: %d + %d = %d"%(i+1, num_one, num_two, num_sum)) connection.recv() - #Sending the password + # Sending the password connection.sendline(bytes("%d"%num_sum, "utf-8")) connection.recv() connection.interactive() diff --git a/linux_and_misc/scripts/binaryaddition.py b/linux_and_misc/scripts/binaryaddition.py @@ -7,19 +7,19 @@ from pwn import * import struct -#Connecting to the server +# Connecting to the server connection = remote("twinpeaks.cs.ucdavis.edu", 30002) connection.recvuntil("Ready") for i in range(0,50): connection.recvuntil(" : ") - #Arrive at the first number and unpack it + # Arrive at the first number and unpack it num_one = struct.unpack("I", connection.recv(4))[0] connection.recvuntil(" + ") - #Arrive at the second number and unpack it + # Arrive at the second number and unpack it num_two = struct.unpack("I", connection.recv(4))[0] num_sum = num_one + num_two print("Equation %d: %d + %d = %d"%(i+1, num_one, num_two, num_sum)) - #Convert the added numbers and send them back + # Convert the added numbers and send them back num_sum = struct.pack("I", num_sum) connection.send(num_sum) connection.interactive() diff --git a/linux_and_misc/scripts/strcmp.py b/linux_and_misc/scripts/strcmp.py @@ -12,13 +12,13 @@ def string_to_integer(s: str) -> int: Keyword arguments: s -- the string to convert to an int """ - #Converts the characters to ascii representations (a=0, z=25) + # Converts the characters to ascii representations (a=0, z=25) num_values = [(ord(char)-97) for char in s][::-1] lst = [] - #Converts the number representation in the list to its base10 value + # Converts the number representation in the list to its base10 value for pos, val in enumerate(num_values): lst.append(val*(26**pos)) - #Return the sum of the character values in base10 + # Return the sum of the character values in base10 return sum(lst) def integer_to_string(num: int, max: int = 19) -> str: @@ -30,11 +30,11 @@ def integer_to_string(num: int, max: int = 19) -> str: """ alphabetized_input = "" for a in range(max,0,-1): - #Divides the number to get an int (0-25/a-z) + # Divides the number to get an int (0-25/a-z) digit = int(num/(26**a)) if int(num/(26**a)) <= 25 else 25 - #Converts the number to the corresponding letter + # Converts the number to the corresponding letter corresponding_character = chr(digit+97) - #Adds the new character to the total string + # Adds the new character to the total string alphabetized_input += corresponding_character num -= digit*(26**a) corresponding_character = chr(int(num)+97) @@ -58,27 +58,27 @@ LO = "aaaaaaaaaaaaaaaaaaaa" HI = "zzzzzzzzzzzzzzzzzzzz" connection = remote("twinpeaks.cs.ucdavis.edu", 30004) while not cracked: - #First run case + # First run case if first_attempt: - #Generates a password + # Generates a password password = passgen(LO, HI) - #Prints challenge + # Prints challenge print(str(connection.recv(), "utf-8")) - #Sends and prints the password + # Sends and prints the password connection.sendline(password) print("Password: %s"%password) first_attempt = False else: response = connection.recvline() previous_pass = password - #Checks the response to perform binary search - if b" -1 " in response: #Password too small + # Checks the response to perform binary search + if b" -1 " in response: # Password too small LO = password password = passgen(LO, HI) - elif b" 1 " in response: #Password too large + elif b" 1 " in response: # Password too large HI = password password = passgen(LO, HI) - else: #Password cracked + else: # Password cracked cracked = True break connection.sendline(password) diff --git a/linux_and_misc/walkthroughs/addition.md b/linux_and_misc/walkthroughs/addition.md @@ -52,20 +52,20 @@ Now, we just have to stick all that in a loop that runs 50 times (and simplify i # 04/01/2020 from pwn import * -#Connecting to the server +# Connecting to the server connection = remote("twinpeaks.cs.ucdavis.edu", 30001) for i in range(0,50): - #Recieving the equation + # Recieving the equation equation = connection.recvline_contains("Question") - #Splitting the equation into the two numbers to add + # Splitting the equation into the two numbers to add numbers = [int(item.strip()) for item in ((equation.split(b":")[1]).strip()).split(b"+")] num_one = numbers[0] num_two = numbers[1] - #Adding the two numbers + # Adding the two numbers num_sum = sum(numbers) print("Equation %d: %d + %d = %d"%(i+1, num_one, num_two, num_sum)) connection.recv() - #Sending the password + # Sending the password connection.sendline(bytes("%d"%num_sum, "utf-8")) connection.recv() connection.interactive() diff --git a/linux_and_misc/walkthroughs/binaryaddition.md b/linux_and_misc/walkthroughs/binaryaddition.md @@ -55,19 +55,19 @@ And now we just have to run it! The finalized code looks like this: from pwn import * import struct -#Connecting to the server +# Connecting to the server connection = remote("twinpeaks.cs.ucdavis.edu", 30002) connection.recvuntil("Ready") for i in range(0,50): connection.recvuntil(" : ") - #Arrive at the first number and unpack it + # Arrive at the first number and unpack it num_one = struct.unpack("I", connection.recv(4))[0] connection.recvuntil(" + ") - #Arrive at the second number and unpack it + # Arrive at the second number and unpack it num_two = struct.unpack("I", connection.recv(4))[0] num_sum = num_one + num_two print("Equation %d: %d + %d = %d"%(i+1, num_one, num_two, num_sum)) - #Convert the added numbers and send them back + # Convert the added numbers and send them back num_sum = struct.pack("I", num_sum) connection.send(num_sum) connection.interactive()