first draft
This commit is contained in:
10
utils/Makefile
Normal file
10
utils/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC=gcc
|
||||
CCOPT=-Wall
|
||||
|
||||
all: hex2bin
|
||||
|
||||
hex2bin: hex2bin.c
|
||||
$(CC) $(CCOPT) -o hex2bin hex2bin.c
|
||||
|
||||
clean:
|
||||
rm -f hex2bin
|
20
utils/README.HEX2BIN
Normal file
20
utils/README.HEX2BIN
Normal file
@ -0,0 +1,20 @@
|
||||
hex2bin is an utility to convert a string in hexadecimal format like
|
||||
"2b2b2b415448300d" (an example to test a stupid modem vulnerability)
|
||||
in the binary equivalent. For example:
|
||||
|
||||
# echo -n "2b2b2b415448300d" | ./hex2bin > modem.string
|
||||
|
||||
# cat modem.string
|
||||
+++ATH0
|
||||
|
||||
# ls -l modem.string
|
||||
-rw-r--r-- 1 antirez users 8 Nov 17 16:01 modem.string
|
||||
|
||||
# hping2 --file ./modem.string -d 8 --icmp target.host.org
|
||||
|
||||
using switch '-r' hex2bin perform exactly the inverse operation.
|
||||
for example:
|
||||
|
||||
echo "antirez" | ./hex2bin -r
|
||||
|
||||
616e746972657a0a
|
63
utils/hex2bin.c
Normal file
63
utils/hex2bin.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* hex2bin - simple hex to bin filter
|
||||
* antirez@invece.org - under GPL version 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
int hex2bin(void)
|
||||
{
|
||||
char hex[3];
|
||||
int d = 0;
|
||||
unsigned char c;
|
||||
int stdin_fd = fileno(stdin);
|
||||
int n_read;
|
||||
|
||||
while((n_read = read(stdin_fd, hex, 2)) > 0)
|
||||
{
|
||||
if (n_read == 1)
|
||||
{
|
||||
if (hex[0] != '\n')
|
||||
{
|
||||
fprintf(stderr,
|
||||
"input parse error, odd digits in hex file\n");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
hex[2] = '\0';
|
||||
sscanf(hex, "%x", &d);
|
||||
c = (unsigned char) d;
|
||||
printf("%c", c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bin2hex(void)
|
||||
{
|
||||
int stdin_fd = fileno(stdin);
|
||||
int n_read;
|
||||
unsigned char c;
|
||||
|
||||
while((n_read = read(stdin_fd, &c, 1)) > 0)
|
||||
{
|
||||
printf("%.2x", c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc >= 2 && strstr(argv[1], "-r"))
|
||||
bin2hex();
|
||||
else
|
||||
hex2bin();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user