반응형
정적 라이브러리 만들기
http://www.darknet.org.uk/2016/07/dmitry-deepmagic-information-gathering-tool/
부제 : dmitry 소스 쪼개서 사용하기
tcp_sock.h
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/uio.h> #include <unistd.h> #define MAX_TCP_CON 9 #define MAX_PART 20 #define STD_MSN_PORT 1863 struct sockaddr_in sock; /* Structure for socket address */ long address; /* Remote IP (4 octet) address */ struct hostent *ph; int tcp_sock; int args[2][1]; char print[512]; struct in_addr **pptr; int bind_sock; int con_sock; int irc_sock; int tcp_socket(char *host, int port); void readData(char *readbuff, int readsize); void sendData(char *sendbuff, int sendsize);
tcp_sock.c
/* TCP Socket header * Coded by James Greig * James@mor-pah.net * Date: 16/06/03 */ /* TCP Socket construction */ #include "tcp_sock.h" #include <string.h> #include <stdio.h> #include <ctype.h> int tcp_socket(char *host, int port) { memset(&sock, '\0', sizeof(sock)); if(isdigit(host[0])) { if ((address = inet_addr(host)) == -1) { printf("Error: Unable to connect - Invalid Host\n"); return 1; } sock.sin_addr.s_addr = address; } else { if(!(ph = gethostbyname(host))) { printf("Error: Unable to connect - Invalid Host\n"); return 2; } pptr = (struct in_addr **) ph->h_addr_list; memcpy(&sock.sin_addr, *pptr, sizeof(struct in_addr)); } sock.sin_family = AF_INET; /* Place port in sock information structure */ sock.sin_port = htons(port); /* open socket */ if(tcp_sock == 0) { if((tcp_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("Unable to connect: Error at socket build\n"); return 3; } /* Connet to remote host */ if(connect(tcp_sock, (struct sockaddr *) &sock, sizeof (sock)) < 0) { printf("Unable to connect: Socket Connect Error\n"); return 4; } return 0; } printf("Socket Error\n"); return 1; } /* TCP Socket Disconnect */ void tcp_sockdcon() { if (close((int) tcp_sock)) printf("close error\n"); tcp_sock = 0; } /* Read Data Function (Data IN)*/ void readData(char *readbuff, int readsize) { memset(readbuff, '\0', readsize); /* Clear read buffer (null) */ read((int) tcp_sock, (char *) readbuff, (int) readsize); /* printf(">> %s\n", readbuff); */ } /* Send Data Function (Data OUT) */ void sendData(char *sendbuff, int sendsize) { write((int) tcp_sock, (char *) sendbuff, (int) sendsize); /* printf("<< %s\n", sendbuff); */ }
컴파일 하기
hacker@ubuntu$ gcc -c tcp_sock.c hacker@ubuntu$ ar rc libtcpsock.a tcp_sock.o hacker@ubuntu$ hacker@ubuntu$ gcc -o lib1_test lib1_test.c -L./ -ltcpsock
lib1_test.c 테스트 소스
#include "tcp_sock.h" #include <stdio.h> #include <string.h> int main( int argc , char ** argv ) { char sendbuff[255]; memset(sendbuff,0x00 , sizeof(sendbuff)); char recvbuff[128]; memset(recvbuff,0x00 , sizeof(recvbuff)); char * host = "testphp.vulnweb.com"; tcp_socket(host,80); snprintf(sendbuff, sizeof(sendbuff), "GET http://%s HTTP/1.0\r\n\r\n", host); sendData(sendbuff, strlen(sendbuff)); while(1){ memset(recvbuff, '\0', sizeof(recvbuff)); readData(recvbuff, sizeof(recvbuff)); if ( recvbuff[0] == '\0' ){ close(tcp_sock); tcp_sock = 0; return 0; }else { printf("Information gathered\n"); printf("data = %s\n", recvbuff); } } return 0; }
lib1_test.c 컴파일하고 실행
hacker@ubuntu$ gcc -o lib1_test lib1_test.c -L./ -ltcpsock ./lib1_test Information gathered data = HTTP/1.1 200 OK Server: nginx/1.4.1 Date: Tue, 19 Jul 2016 05:10:37 GMT Content-Type: text/html Connection: close X-PoweredGET http://testphp.vulnweb.com HTTP/1.0 Information gathered data = -By: PHP/5.3.10-1~lucid+2uwsgi2
반응형
'C 언어' 카테고리의 다른 글
strdup (0) | 2016.07.20 |
---|---|
공유(shared) 라이브러리 만들기 (0) | 2016.07.19 |
copy file (0) | 2016.07.12 |
binary search (0) | 2016.07.12 |
search (0) | 2016.07.12 |