Skip to content

Commit d827c6a

Browse files
committed
v1.3: Remove DEBUG.exe 64k limitation, Compression option & Bug fixes
1 parent 78263ac commit d827c6a

File tree

2 files changed

+200
-97
lines changed

2 files changed

+200
-97
lines changed

README.md

+52-33
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,79 @@
11
# exe2hex
22

3-
Inline file transfer method using `debug.exe` and/or PowerShell.
3+
Inline file transfer using in-built Windows tools (`debug.exe` or PowerShell).
44

55
- - -
66

77
### Overview
88

9+
exe2hex encodes an executable binary file into ASCII text format.
910

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).
1112

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).
1314

14-
```Binary EXE -> ASCII text -> Binary EXE```
15+
```Binary EXE -> ASCII Text -> *Transfer* -> Binary EXE```
1516

16-
![](https://i.imgur.com/kMcqHNq.png)
17+
![](https://i.imgur.com/UJjgq7q.png)
1718

1819
- - -
1920

20-
### Quick usage
21+
### Quick Guide
2122

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`)
2425

2526
#### Example Usage
2627

2728
```bash
2829
$ python3 exe2hex.py -x /usr/share/windows-binaries/sbd.exe
29-
[*] exe2hex v1.2
30+
[*] exe2hex v1.3
3031
[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
3334
$
3435
```
3536

3637
```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
4045
$
4146
```
4247

4348
```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
4651
[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
5454
$
5555
```
5656

5757
#### Help
5858

5959
```bash
6060
$ python3 exe2hex.py -h
61-
[*] exe2hex v1.2
61+
[*] exe2hex v1.3
6262
Usage: exe2hex.py [options]
6363

6464
Options:
6565
-h, --help show this help message and exit
6666
-x EXE The EXE binary file to convert
6767
-s Read from STDIN
6868
-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)
7070
-e URL encode the output
7171
-r TEXT pRefix - text to add before the command on each line
7272
-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
7474
-v Enable verbose mode
75+
-c Clones and compress the file before converting (-cc for higher
76+
compression)
7577
$
7678
```
7779

@@ -80,12 +82,29 @@ $
8082
### Methods/OS Support
8183

8284
+ **`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!
8689
+ **PowerShell (PoSh mode - `-p`)**
87-
+ Supports both Windows x86 & x64.
90+
+ Supports both x86 & x64 OSs.
8891
+ 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

Comments
 (0)