|
1 | 1 | # exe2hex
|
2 | 2 |
|
3 |
| -Inline file transfer method using `debug.exe` and/or PowerShell. |
| 3 | +Inline file transfer using in-built Windows tools (`debug.exe` or PowerShell). |
4 | 4 |
|
5 | 5 | - - -
|
6 | 6 |
|
7 | 7 | ### Overview
|
8 | 8 |
|
| 9 | +exe2hex encodes an executable binary file into ASCII text format. |
9 | 10 |
|
10 |
| -Encodes a executable binary file into ASCII text format. |
| 11 | +The result then can be transferred to the target machine (It is much easier to echo a ASCII file than binary data). |
11 | 12 |
|
12 |
| -Restores using `DEBUG.exe` (BATch - x86) and/or PowerShell (PoSh - x86/x64). |
| 13 | +Upon executing exe2hex's output file, the original program is restored by using `DEBUG.exe` or PowerShell (which are pre-installed by default). |
13 | 14 |
|
14 |
| -```Binary EXE -> ASCII text -> Binary EXE``` |
| 15 | +```Binary EXE -> ASCII Text -> *Transfer* -> Binary EXE``` |
15 | 16 |
|
16 |
| - |
| 17 | + |
17 | 18 |
|
18 | 19 | - - -
|
19 | 20 |
|
20 |
| -### Quick usage |
| 21 | +### Quick Guide |
21 | 22 |
|
22 |
| - + Input with a file (`-x /path/to/binary.exe`) or STDIN (`-s`) |
23 |
| - + Output to BAT (`-b /path/to/debug.bat`) and/or PoSH (`-p powershell.cmd`) |
| 23 | + + Input using a file (`-x /path/to/binary-program.exe`) or STDIN (`-s`) |
| 24 | + + Output to BATch (`-b file.bat`) and/or PoSH (`-p powershell.cmd`) |
24 | 25 |
|
25 | 26 | #### Example Usage
|
26 | 27 |
|
27 | 28 | ```bash
|
28 | 29 | $ python3 exe2hex.py -x /usr/share/windows-binaries/sbd.exe
|
29 |
| -[*] exe2hex v1.2 |
| 30 | +[*] exe2hex v1.3 |
30 | 31 | [i] Outputting to /root/sbd.bat (BATch) and /root/sbd.cmd (PoSh)
|
31 |
| -[+] Successfully wrote (BAT): /root/sbd.bat |
32 |
| -[+] Successfully wrote (PoSh): /root/sbd.cmd |
| 32 | +[+] Successfully wrote (BATch) /root/sbd.bat |
| 33 | +[+] Successfully wrote (PoSh) /root/sbd.cmd |
33 | 34 | $
|
34 | 35 | ```
|
35 | 36 |
|
36 | 37 | ```bash
|
37 |
| -$ ./exe2hex.py -x /usr/share/windows-binaries/nc.exe -b /var/www/html/nc.txt |
38 |
| -[*] exe2hex v1.2 |
39 |
| -[+] Successfully wrote (BAT): /var/www/html/nc.txt |
| 38 | +$ ./exe2hex.py -x /usr/share/windows-binaries/nc.exe -b /var/www/html/nc.txt -cc |
| 39 | +[*] exe2hex v1.3 |
| 40 | +[i] Attempting to clone and compress |
| 41 | +[i] Creating temporary file /tmp/tmpkel8b4f0 |
| 42 | +[+] Compression (strip) was successful! (0.0% saved) |
| 43 | +[+] Compression (UPX) was successful! (50.9% saved) |
| 44 | +[+] Successfully wrote (BATch) /var/www/html/nc.txt |
40 | 45 | $
|
41 | 46 | ```
|
42 | 47 |
|
43 | 48 | ```bash
|
44 |
| -$ cat /usr/share/windows-binaries/whoami.exe | python3 exe2hex.py -s -b debug.bat -p ps.cmd |
45 |
| -[*] exe2hex v1.2 |
| 49 | +$ cat /usr/share/windows-binaries/whoami.exe | python exe2hex.py -s -b debug.bat -p ps.cmd |
| 50 | +[*] exe2hex v1.3 |
46 | 51 | [i] Reading from STDIN
|
47 |
| -[!] ERROR: Input is larger than 65536 bytes (BATch/DEBUG.exe limitation) |
48 |
| -[i] Attempting to clone and compress |
49 |
| -[i] Creating temporary file /tmp/tmpfypsf9if |
50 |
| -[i] Running strip on /tmp/tmpfypsf9if |
51 |
| -[+] Compression was successful! |
52 |
| -[+] Successfully wrote (BAT): /root/debug.bat |
53 |
| -[+] Successfully wrote (PoSh): /root/ps.cmd |
| 52 | +[+] Successfully wrote (BATch) /root/debug.bat |
| 53 | +[+] Successfully wrote (PoSh) /root/ps.cmd |
54 | 54 | $
|
55 | 55 | ```
|
56 | 56 |
|
57 | 57 | #### Help
|
58 | 58 |
|
59 | 59 | ```bash
|
60 | 60 | $ python3 exe2hex.py -h
|
61 |
| -[*] exe2hex v1.2 |
| 61 | +[*] exe2hex v1.3 |
62 | 62 | Usage: exe2hex.py [options]
|
63 | 63 |
|
64 | 64 | Options:
|
65 | 65 | -h, --help show this help message and exit
|
66 | 66 | -x EXE The EXE binary file to convert
|
67 | 67 | -s Read from STDIN
|
68 | 68 | -b BAT BAT output file (DEBUG.exe method - x86)
|
69 |
| - -p POSH PoSh output file (PowerShell method - x64/x86) |
| 69 | + -p POSH PoSh output file (PowerShell method - x86/x64) |
70 | 70 | -e URL encode the output
|
71 | 71 | -r TEXT pRefix - text to add before the command on each line
|
72 | 72 | -f TEXT suFfix - text to add after the command on each line
|
73 |
| - -l INT Maximum hex values per line |
| 73 | + -l INT Maximum HEX values per line |
74 | 74 | -v Enable verbose mode
|
| 75 | + -c Clones and compress the file before converting (-cc for higher |
| 76 | + compression) |
75 | 77 | $
|
76 | 78 | ```
|
77 | 79 |
|
|
80 | 82 | ### Methods/OS Support
|
81 | 83 |
|
82 | 84 | + **`DEBUG.exe` (BATch mode - `-b`)**
|
83 |
| - + Every version of Windows x86 (No x64 support). |
84 |
| - + Useful for legacy versions of Windows (e.g. XP/2000). |
85 |
| - + Has a limitation of 64k file size for binary files. |
| 85 | + + Supports x86 OSs (No x64 support). |
| 86 | + + Useful for legacy versions of Windows (e.g. Windows XP/Windows 2000). |
| 87 | + + Pre-installed by default. Works out of the box. |
| 88 | + + ~~Limitation of 64k file size for binary programs.~~ Creates multiple parts and joins with `copy /b` so this is not an issue any more! |
86 | 89 | + **PowerShell (PoSh mode - `-p`)**
|
87 |
| - + Supports both Windows x86 & x64. |
| 90 | + + Supports both x86 & x64 OSs. |
88 | 91 | + Aimed at more "recent" versions of Windows.
|
89 |
| - + Powershell was first integrated into core OS with Windows 7/Windows Server 2008 R2. |
90 |
| - + Windows XP SP2, Windows Server 2003 & Windows Vista requires PowerShell to be pre-installed. |
91 |
| - + This is **not** a `.ps1` file (pure powershell). It only calls powershell at the end to convert. |
| 92 | + + PowerShell was first integrated into core OS with Windows 7/Windows Server 2008 R2. |
| 93 | + + Windows XP SP2, Windows Server 2003 & Windows Vista requires PowerShell to be pre-installed. |
| 94 | + + This is **not** a `.ps1` file (pure PowerShell). It only calls PowerShell at the end to convert. |
| 95 | + |
| 96 | +- - - |
| 97 | + |
| 98 | +### Features |
| 99 | + |
| 100 | +**Primary purpose**: Convert a binary program into a ASCII HEX file which can be restored using in-built OS programs. |
| 101 | + |
| 102 | ++ Able to use a file or standard input |
| 103 | ++ Work on old and new versions of Windows without any 3rd party programs. |
| 104 | ++ Supports x86 & x64. |
| 105 | ++ Includes a function to compress the file. |
| 106 | ++ URL encode the output. |
| 107 | ++ Option to add prefix and suffix text to each line. |
| 108 | ++ Able to set a maximum HEX length. |
| 109 | + |
| 110 | +Note: This is nothing new. [The core idea has been around since 2003](https://www.blackhat.com/presentations/bh-asia-03/bh-asia-03-chong.pdf) _(if not before!)_. |
0 commit comments