发送一个二进制文件(逐行)与Netcat的套接字服务器 [英] Send a binary file (line by line) to a socket server with Netcat

查看:869
本文介绍了发送一个二进制文件(逐行)与Netcat的套接字服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我想除了archieve同一个分拆到这个堆栈溢出问题一对夫妇的调整的。

我想连接到主机时,通过线路传送一个二进制文件,线,并有一对中的每一行之间的延迟秒...和它必须在相同的连接。我要发送的字符串大多是基于文本的,但有一些非打印字符的行了。

这是一个字符串/线路我想送(千每个文件的行)的例子:

<零> E<零><零> 00326513,6598,不,8日,2Z<零>

<空方式&g​​t; 值是十六进制值 0×00

我已经rewitten我的问题从它的第一项,但 @mzet 回答我对我原来的问题是我的问题是,文本才,但后来我发现我的字符串有这些 0×00 字符里面,我不能在第一次看到。我想用他的回答为基础,因为我觉得它差不多的作品,但它可能需要一个调整,所以这是他的功劳,不是我的。

如果我有3行的文件:

 <&空GT; E<&空GT;<&空GT; 00370513,6598,不,8日,2Z<&空GT;
<&空GT; F<&空GT;<&空GT; 00891548,6598,是的,8日,3Z<&空GT;
<&空GT; F<&空GT;<&空GT; 00129525,6598,是的,8日,2Z<&空GT;

然后我想我可以调整的 @mzet 答案,并替换<零> 我的文件中值\\ X00 并设置 -e 回声命令:

  [根@ SRV]#mkfifo子的/ tmp / fifoIn;猫的/ tmp / fifoIn |数控本地主机2222&安培;
[根@ SRV]#猫MYFILE |而读线;做回声-ne $线;睡眠2;完成>的/ tmp / fifoIn

当我这样做,我可以看到 X00 在服务器端:

  [根@ SRV]#NC -l 2222
x00ex00x0000370513,6598,不,8日,2zx00
x00fx0000891548,6598,是的,8日,3zx00
x00fx00x0000129525,6598,是的,8日,2zx00

时可以发送一个二进制文件(文本?)文件作为我想要的吗?如果它是不可能通过线上发送一个文件,线,是它,然后可以发送的时候一根弦几千?绝对必要的,他们并不需要是唯一或在一个文件中,因为我可以用相同的字符串重演管理。

编辑#1

为什么我的脚本只发送一行到服务器(我预计4号线),之后它只是暂停(?)永远。客户端(也服务器)将关闭它的连接,但不附带任何错误:

  RM -f / tmp目录/ fifofile
mkfifo子的/ tmp / fifofile
猫的/ tmp / fifofile | NC 192.168.20.6 5000&安培;
睡眠1I =0而[$ I -lt 4]

  回声$ I
  回声-ne\\ x00e \\ X00 \\ x00001212dsfdsfdsfsdfsdfsdfdsf \\ X00|三通的/ tmp / fifofile
  睡眠1
  I = $ [$ I + 1]
DONE


很多的尝试,拉我的头发后,我终于想通了,我可以用的 NCAT 的,而不是作为Netcat的NCAT可以执行的命令。

先从NCAT我套接字服务器端口的连接 5000 并执行脚本 ./ sendlines.sh

NCAT --exec./sendlines.sh192.168.1.10 5000

./ sendlines.sh 将派出4行两秒各行之间的延迟:

 #!/斌/庆典

#sendlines.sh,V1.00,初始版本

I =0
而[$ I -lt 4]

  回声-ne\\ x00e \\ X00 \\ x0000370513,6598,不,8日,2Z \\ X00
  睡眠2
  I = $ [$ I + 1]
DONE

我还没有想出如何发送一个二进制文件,一行行,但这不是绝对必要的,因为我可以通过发送相同的字符串很多次管理。

如果你知道一种方法来发送一个二进制文件,一行行,这将是伟大的,因为这将是对我最好的解决方案。

As a spin off to this Stack Overflow question I want to archieve the same except for a couple of tweaks.

I want to connect to a host, send a binary file, line by line, and have a couple of seconds of delay between each line... and it must be in the same connection. The strings I want to send are mostly textbased but there are a couple of non-printable chars in the line.

This is an example of a string/line I want to send (thousands of lines per file):

<null>e<null><null>00326513,6598,no,8,,2z<null>

The <null> value is the HEX value 0x00.

I have rewitten my question from its first entry but @mzet answered me on my original question as my question was text-only then but I later on discovered that my string had these 0x00 chars inside which I could not see at first. I want to use his answer as a base as I think it almost works but it may need a tweak so this is his contribution, not mine.

If I have a file with 3 lines:

<null>e<null><null>00370513,6598,no,8,,2z<null>
<null>f<null><null>00891548,6598,yes,8,,3z<null>
<null>f<null><null>00129525,6598,yes,8,,2z<null>

I then thought I could tweak @mzet answer and replace the <null> values inside my file with \x00 and set -e on the echo command:

[root@srv]# mkfifo /tmp/fifoIn; cat /tmp/fifoIn | nc localhost 2222 &
[root@srv]# cat myfile | while read line; do echo -ne $line; sleep 2; done > /tmp/fifoIn

When I do that, I can see the x00 on the serverside:

[root@srv]# nc -l 2222
x00ex00x0000370513,6598,no,8,,2zx00
x00fx0000891548,6598,yes,8,,3zx00
x00fx00x0000129525,6598,yes,8,,2zx00

Is it possible to send a binary (text?) file as I want? And if it it not possible to send a file, line by line, is it then possible to send one string several thousands of times? Strictly necessary they don't need to be unique or in a file as I could manage with the same string repeating itself.

EDIT #1

Why is my script only sending one line to the server (I would expect 4 lines) afterwards it is just pausing(?) forever. The client (nor the server) closes its connection but it doesn't come with any errors:

rm -f /tmp/fifofile
mkfifo /tmp/fifofile
cat /tmp/fifofile | nc 192.168.20.6 5000 &
sleep 1

i="0"

while [ $i -lt 4 ]
do
  echo "$i"
  echo -ne "\x00e\x00\x00001212dsfdsfdsfsdfsdfsdfdsf\x00" | tee /tmp/fifofile
  sleep 1
  i=$[$i+1]
done

解决方案

After a lot of trying and pulling my hair I finally figured out that I could use NCat instead of Netcat as NCat can execute a command.

Start a connection with NCat to my socket server on port 5000 and execute the script ./sendlines.sh:

ncat --exec "./sendlines.sh" 192.168.1.10 5000

./sendlines.sh will send 4 lines with a delay of two seconds between each line:

#!/bin/bash
#
# sendlines.sh, v1.00, initial release
#
i="0"
while [ $i -lt 4 ]
do
  echo -ne "\x00e\x00\x0000370513,6598,no,8,,2z\x00"
  sleep 2
  i=$[$i+1]
done

I have not figured out how to send a binary file, line by line, but this is not strictly necessary as I can manage by sending the same string many times.

If you know a way to send a binary file, line by line, it would be great as it would be the best solution for me.

这篇关于发送一个二进制文件(逐行)与Netcat的套接字服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆