Last active
April 5, 2024 05:11
-
-
Save caueb/433afcc6c5dbfed34bd23cbefa5df2c0 to your computer and use it in GitHub Desktop.
Convert binary to IPv4 format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ipaddress import ip_address | |
import sys | |
if len(sys.argv) < 2: | |
print("Usage: %s <shellcode_file>" % sys.argv[0]) | |
sys.exit(1) | |
with open(sys.argv[1], "rb") as f: | |
chunk = f.read(4) | |
ip_addresses = [] | |
while chunk: | |
if len(chunk) < 4: | |
padding = 4 - len(chunk) | |
chunk = chunk + (b"\x90" * padding) | |
ip_addresses.append(ip_address(chunk)) | |
break | |
ip_addresses.append(ip_address(chunk)) | |
chunk = f.read(4) | |
print("const char* IPv4s[] = {") | |
counter = 0 | |
for i in range(0, len(ip_addresses), 8): | |
line_ips = ip_addresses[i:i+8] | |
line = ', '.join(['"{}"'.format(ip) for ip in line_ips]) | |
if i + 8 < len(ip_addresses): | |
print(' {},'.format(line)) | |
else: | |
print(' {}'.format(line)) | |
print("};") | |
print("#define NumberOfElements", len(ip_addresses)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment