I need to configure the back shell to connect to a device connected to the Internet via a GPRS modem.
When special conditions arise, I run this command on a public server with a fixed ip
nc -l 65535
then I will make this code run (now I am directly connected to the device using the test cable) (and yes, the plug is useless in this case, but I will need it in my final script, so I saved it)
#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;
p = fork();
if (p == 0)
{
char *shell[2];
int i,fd;
struct sockaddr_in sin;
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(fd, (struct sockaddr *)&sin,sizeof(struct sockaddr_in));
for(i=0; i<3; i++)
dup2(fd, i);
shell[0] = "/bin/bash";
shell[1] = 0;
if (execve(shell[0], shell, NULL) == -1)
printf("error\n");
exit(0);
}
return 0;
}
int main()
{
reverse_shell();
}
The back shell is set up, but as you can see, I have no clue and it looks a bit confusing.
[root@public-server tmp]# nc -lv 65535
Connection from yyy.yyy.yyy.yyy port 65535 [tcp
In addition, I need to use scp, but messages continue to appear at the device’s prompt, and not on the server with the reverse connection
server with reverse connection:
[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
device message:
root@device:/tmp
root@device:/tmp
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)?
, ?