【发布时间】:2015-10-12 13:52:39
【问题描述】:
我需要设置一个反向 shell 才能连接到通过 GPRS 调制解调器连接到互联网的设备。
当出现特殊情况时,我会在固定 ip 的公共服务器上启动此命令
nc -l 65535
然后我将运行此代码(现在我通过电缆直接连接到设备以进行测试)(是的,在这种情况下叉子没用,但在我的最终场景中我会需要它,所以我保留了它)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int reverse_shell()
{
pid_t p = 0;
/* fork */
p = fork();
if (p == 0)
{
char *shell[2];
int i,fd;
struct sockaddr_in sin;
/* open socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("MY SERVER PUBLIC IP ADDRESS");
sin.sin_port = htons(65535);
/* connect! */
connect(fd, (struct sockaddr *)&sin,sizeof(struct sockaddr_in));
/* assign three first fd (input/output/err) to open socket */
for(i=0; i<3; i++)
dup2(fd, i);
/* build array */
shell[0] = "/bin/bash";
shell[1] = 0;
/* start the reverse shell */
if (execve(shell[0], shell, NULL) == -1)
printf("error\n");
exit(0);
}
return 0;
}
int main()
{
reverse_shell();
}
反向 shell 已设置,但如您所见,我没有收到任何提示,而且看起来有点混乱。
[root@public-server tmp]# nc -lv 65535
Connection from yyy.yyy.yyy.yyy port 65535 [tcp/*] accepted
cd /etc
ls *hosts*
hosts
hosts.allow
hosts.deny
另外,我需要使用scp,但消息不断出现在设备提示上而不是反向连接的服务器上
反向连接服务器:
[root@public-server tmp]# nc -lv 65535
Connection from yyy.yyy.yyy.yyy port 65535 [tcp/*] accepted
ls /etc/hosts
/etc/hosts
scp /etc/hosts xxx.xxx.xxx.xxx:/tmp/
Host key verification failed.
lost connection
设备提示:
root@device:/tmp# ./a.out
root@device:/tmp# The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is aa:e6:aa:1d:aa:a5:c2:fd:aa:4c:4f:e7:aa:34:aa:78.
Are you sure you want to continue connecting (yes/no)?
我可以做些什么来解决这个问题并获得一个稳定可用的反向外壳?
【问题讨论】:
-
根本不起作用。连接已建立,但没有输入/输出