-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellcode_not_in_data.py
37 lines (27 loc) · 973 Bytes
/
shellcode_not_in_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import secrets
def binary_to_hex_string(file_path):
with open(file_path, 'rb') as file:
binary_data = file.read()
hex_string = binary_data.hex()
return hex_string
def generate_c_code(hex_string, array_name):
array_size = len(hex_string)
random_string = secrets.token_hex(array_size//4)
c_code = f"char {array_name}[{array_size //2}] = \"{random_string}\"; \n\n\n"
c_code += ''.join([f"{array_name}[{i // 2}] = (char)0x{hex_string[i:i+2]}; " for i in range(0, len(hex_string), 2)])
return c_code
def main():
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <file.bin_path>")
sys.exit(1)
file_path = sys.argv[1]
array_name = 'buf'
# Convert binary to hex string
hex_string = binary_to_hex_string(file_path)
# Generate C code
c_code = generate_c_code(hex_string, array_name)
# Print the generated C code
print(c_code)
if __name__ == "__main__":
main()