Terminal escape character for hexadecimal input
Solution 1
You can use echo -e
, (which is what I think richardhoskins meant.) Like this:
/bin/echo -n -e "\x01\x00\xaf\x0f\xe1" | netcat -u somewhere 1234
# -n: no newline at end, -e: interpret escapes
If your echo implementation is old, (or simply not GNU-encrusted,) the old-school way is to use octal:
/bin/echo -n -e "\001\000\257\017\341" | netcat -u somewhere 1234
Yes, octal is way, way old-school. Look at ibase
and obase
in the man for bc
. Check to see if echo does the right thing with od
("octal dump") "od -tx1" for hex, "od -to1" for octal.
Solution 2
A simple approach, though not quite what you are looking for...
Use a hex editor to create a file with the bytes in that you want to send (you mention gnome so you may already have ghex but any hex editor should be fine). For short hex sequences I usually include the hex as part of the name (e.g. test0x0100af0fe1).
Then just redirect the content into netcat
, e.g.:
mas@voco:~$ nc -o testout 127.0.1.1 80 < test0x0100af0fe1
^C
mas@voco:~$ cat testout
> 00000000 01 00 af 0e 10 # .....
mas@voco:~$
This has the disadvantage of having to prepare a separate file but it makes replication and documentation of tests easier.
Solution 3
you have to use perl in terminal example:
./program perl -e' print "\x41\x60\x34\x45"'
it will send this hex address to program. It is used often in buffer overrun as hexa address input. The page does not show everything I typed. Look on google for buffer overflow. Those pages show you everything. Here are missing back single quotes in front of perl one and second at the end of a whole input.
Rupertt Wind
Updated on September 17, 2022Comments
-
Rupertt Wind over 1 year
In my usual gnome-terminal I do a
netcat -u somewhere 1234
to start sending UDP packets to somewhere. I need to transmit the following 5 bytes, written in hexadecimal: "01 00 af 0f e1". Now how do I type a escape sequence into my terminal that causes it to send these exact 5 bytes to stdin of netcat?
Update: Just to clarify. I know several ways of actually inputting the bytes I want to the program. That is not the question. The question is what sequence of keystrokes do I type into my terminal, after the program is launched, to input a hexadecimal character that is not otherwise represented on my keyboard. (Such as 0x00, 0x01, or 0x0f.)
I am starting to think it is simply not possible, however I would be a bit surprised if that is the conclusion.
-
Rupertt Wind almost 15 yearsNope, just tried it, it does not escape anything in the terminal. Typing "0xaf" becomes "30 78 61 66 0a" as input to the program.
-
Rupertt Wind almost 15 yearsI am using bash, but I would think only the terminal mattered. The input is going directly to the program (netcat).
-
Richard Hoskins almost 15 yearsEdited to \xHH from 0xHH.
-
Rupertt Wind almost 15 yearsThanks, but again, the input is just "5c 78 61 66 0a". Neither 0x nor \x escapes anything in the terminal. :/
-
Rupertt Wind almost 15 yearsI will probably end up using a solution like this, but I really thought there was a way to escape input in the terminal so that I may type the hexadecimal representation of a character and the terminal will translate it before sending it as input to the program. I like the idea of creating files with the content in the filename, it is exactly very short strings I have to transmit, thanks.