-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
177 lines (129 loc) · 5.08 KB
/
README
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Binmay - command line binary search and replace
Copyright (C) 2004-2011 Sean Loaring
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Email: [email protected]
Web Site: http://www.filewut.com/spages/page.php/software/binmay
Introduction
------------
Binmay is a simple, little program that searches for a string of binary in a
file or stream and replaces it with another string of binary.
Outputting Raw Binary (-p)
--------------------------
Binmay will convert a string into raw binary and dump it with the -p option:
sloaring@dumpy:~$ binmay -p "61 62 63 64 65 66 67"|hd
00000000 61 62 63 64 65 66 67 |abcdefg|
00000007
Parameter String Format (-p, -s, -S, -r, -R)
--------------------------------------------
By default all parameter strings are treated as hex. Non-hex characters are
simply ignored:
$ binmay -p "61-62-63-64-65-66-67"|hd
00000000 61 62 63 64 65 66 67 |abcdefg|
00000007
$ binmay -p "61-ghijklmnopqrs62-63-64-65-66-67"|hd
00000000 61 62 63 64 65 66 67 |abcdefg|
00000007
Paramter strings can also be prefixed with 'h:', 'b:', 't:' and 'f:' denoting
hex, binary, text and file input.
$ binmay -p "h:63 61 74"
cat
$ binmay -p 'b:01100011 01100001 01110100'
cat
$ binmay -p "t:this is text"
this is text
$ echo 'monkey' >tmpfile
$ binmay -p "f:tmpfile"
monkey
Searching
---------
If only the -s parameter is specified then binmay will output a list of offsets
and matching patterns, followed by a match count:
$ binmay -p "00 00 50 00 00 00 50" | binmay -s 50
0x2:50
0x6:50
Matches: 2
$ binmay -p "00 00 50 00 00 00 50" | binmay -s 't:P'
0x2:50
0x6:50
Matches: 2
$ binmay -p "00 00 50 00 00 00 50" | binmay -s 'b:01010000'
0x2:50
0x6:50
Matches: 2
# Look look at some of the bytes surrounding an NK key prefix (6e6b) in
# a windows registry file
$ binmay -s 6e6b0000000000000000000000 -S 'ffff0000000000000000000000' -i ntuser.dat
0x1024:6e 6b 2c 00 a2 56 f4 5a 7a e1 c8 01 00
0x11bc:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x134c:6e 6b 20 00 e6 ef 97 33 3f e1 c8 01 00
0x13bc:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x14c4:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x15d4:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x16dc:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x17dc:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x191c:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x19f4:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x1b04:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x1c04:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x1c64:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x1d24:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x1e24:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x1f0c:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x2024:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x214c:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
0x2234:6e 6b 20 00 8e f2 a3 c8 3e e1 c8 01 00
...
0x7e228:6e 6b 00 00 28 00 03 00 04 00 ef be e9
0x7e274:6e 6b 20 00 d0 c7 93 49 89 e1 c8 01 00
0x7e2e4:6e 6b 20 00 6c 28 63 32 89 e1 c8 01 00
0x7e85c:6e 6b 20 00 b4 79 85 49 89 e1 c8 01 00
0x7e8cc:6e 6b 20 00 b4 79 85 49 89 e1 c8 01 00
0x7e994:6e 6b 20 00 76 65 91 49 89 e1 c8 01 00
0x7ed72:6e 6b 73 00 00 00 e0 ff ff ff 76 6b 04
0x7f17c:6e 6b 20 00 d0 6a 75 5b 89 e1 c8 01 00
0x7f1fc:6e 6b 20 00 d0 6a 75 5b 89 e1 c8 01 00
0x7f254:6e 6b 20 00 2a cd 77 5b 89 e1 c8 01 00
0x7f522:6e 6b 73 e4 07 00 18 00 00 00 f0 e3 07
Matches: 1047
Replacing
---------
Binmay can replace the strings it searches for with other strings.
To replace all instances of "ff ff af" in infile with "aa aa aa" in outfile:
binmay -s "ff ff af" -r "aa aa aa" -i infile -o outfile
To delete all instances of "ff 00"
binmay -s "ff 00" -r ""
To replace all instances of "ff fX af" with "aa aa aa aa aa":
binmay -s "ff ff af" -S "ff f0 ff" -r "aa aa aa aa aa"
Search Masking
--------------
One can apply a bitwise mask to the search string.
$ binmay -p "00 00 50 00 00 00 50 51 52 53" | \
binmay -s 50 -S "f0"
0x2:50
0x6:50
0x7:51
0x8:52
0x9:53
Matches: 5
And everything found can be replaced
$ binmay -p "00 00 50 00 00 00 50 51 52 53" | \
binmay -s 50 -S "f0" -r "11" | hd
00000000 00 00 11 00 00 00 11 11 11 11 |..........|
0000000a
Replace Masking
---------------
You can selectively replace sections of found strings with masks.
$ binmay -p "00 00 50 00 00 00 50 51 52 53"| \
binmay -s 50 -S "f0" -r "90" -R "f0" | hd
00000000 00 00 90 00 00 00 90 91 92 93 |..........|
0000000a