Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:sh0/airown.git
Browse files Browse the repository at this point in the history
Conflicts:
	src/pk_inject_tcp.c
  • Loading branch information
Siim Meerits committed Aug 24, 2010
2 parents 832efdd + f1b4814 commit 8260623
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/pk_inject_tcp.c
Expand Up @@ -38,7 +38,7 @@ void inj_tcp(st_ao_packet* pck, guint8* pl_data, guint32 pl_size)
//printf("* injecting: %s\n", response_data);

// Sequence
guint32 tcp_seq = ntohl(pck->m4.tcp.hdr->ack_seq);
guint32 tcp_seq = ntohl(pck->m4.tcp.hdr->th_ack);

// Device MTU
guint32 mtu = 1000;
Expand Down Expand Up @@ -71,7 +71,7 @@ static void inj_tcp_raw(st_ao_packet* pck, guint8* rsp_data, guint32 rsp_len, gu
printf("[inj] sending! len=%u\n", rsp_len);

// Libnet wants the data in host-byte-order
u_int tcp_ack = ntohl(pck->m4.tcp.hdr->seq) + (ntohs(pck->m3.ipv4.hdr->ip_len) - pck->m3.ipv4.hdr->ip_hl * 4 - pck->m4.tcp.hdr->doff * 4);
u_int tcp_ack = ntohl(pck->m4.tcp.hdr->th_seq) + (ntohs(pck->m3.ipv4.hdr->ip_len) - pck->m3.ipv4.hdr->ip_hl * 4 - pck->m4.tcp.hdr->th_off * 4);

// Timestamps - sometimes timestamps are added to the TCP packets to check
// ping times. We may respond also with timestamp added to our payload
Expand Down Expand Up @@ -104,8 +104,8 @@ static void inj_tcp_raw(st_ao_packet* pck, guint8* rsp_data, guint32 rsp_len, gu

// Build TCP header
pck->ao_inst->ln_tcp_t = libnet_build_tcp(
ntohs(pck->m4.tcp.hdr->dest), // source port
ntohs(pck->m4.tcp.hdr->source), // dest port
ntohs(pck->m4.tcp.hdr->th_dport), // source port
ntohs(pck->m4.tcp.hdr->th_sport), // dest port
*tcp_seq, // sequence number
tcp_ack, // ack number
tcp_flags, // flags
Expand Down
22 changes: 11 additions & 11 deletions src/pk_layer4.c
Expand Up @@ -25,28 +25,28 @@
// Functions
void pck_tcp_read(st_ao_packet* pck)
{
if (pck->m4_size >= sizeof(struct tcphdr)) {
if (pck->m4_size >= sizeof(struct libnet_tcp_hdr)) {
// Header
pck->m4.tcp.hdr = (struct tcphdr*) pck->m4_data;
pck->m4.tcp.hdr = (struct libnet_tcp_hdr*) pck->m4_data;

// Lengths and offsets
guint16 tcp_len = 0;
if (pck->m3_type == AO_M3_IPV4) {
tcp_len = ntohs(pck->m3.ipv4.hdr->ip_len) - (pck->m3.ipv4.hdr->ip_hl * 4) - (pck->m4.tcp.hdr->doff * 4);
tcp_len = ntohs(pck->m3.ipv4.hdr->ip_len) - (pck->m3.ipv4.hdr->ip_hl * 4) - (pck->m4.tcp.hdr->th_off * 4);
} else if (pck->m3_type == AO_M3_IPV6) {
tcp_len = ntohs(pck->m3.ipv4.hdr->ip_len) - sizeof(struct libnet_ipv6_hdr) - (pck->m4.tcp.hdr->doff * 4);
tcp_len = ntohs(pck->m3.ipv4.hdr->ip_len) - sizeof(struct libnet_ipv6_hdr) - (pck->m4.tcp.hdr->th_off * 4);
} else {
return;
}
gint32 tcp_off = (gint32)(pck->m4.tcp.hdr->doff * 4) - sizeof(struct tcphdr);
gint32 tcp_off = (gint32)(pck->m4.tcp.hdr->th_off * 4) - sizeof(struct libnet_tcp_hdr);
if (tcp_off < 0 || tcp_off + tcp_len > pck->m4_size) {
//printf("* tcph! offset/size problem! tcp_len=%u, tcp_off=%d, tcp_size=%u\n", tcp_len, tcp_off, pck->m4_size);
return;
}

// Options
pck->m4.tcp.ts = NULL;
gint32 opt_len = (pck->m4.tcp.hdr->doff * 4) - 20;
gint32 opt_len = (pck->m4.tcp.hdr->th_off * 4) - 20;
//g_print("[dbg] opt_len=%d\n", opt_len);
if (opt_len > 0) {
guint8* opt_ptr = pck->m4_data + 20;
Expand Down Expand Up @@ -91,19 +91,19 @@ void pck_tcp_free(st_ao_packet* pck)

void pck_udp_read(st_ao_packet* pck)
{
if (pck->m4_size >= sizeof(struct udphdr)) {
if (pck->m4_size >= sizeof(struct libnet_udp_hdr)) {
// Header
pck->m4.udp.hdr = (struct udphdr*) pck->m4_data;
pck->m4.udp.hdr = (struct libnet_udp_hdr*) pck->m4_data;

// Lengths and offsets
guint16 udp_len = ntohs(pck->m4.udp.hdr->len);
guint16 udp_len = ntohs(pck->m4.udp.hdr->uh_ulen);
if (udp_len > pck->m4_size) {
return;
}

// Set payload
pck->pl_data = pck->m4_data + sizeof(struct udphdr);
pck->pl_size = udp_len - sizeof(struct udphdr);
pck->pl_data = pck->m4_data + sizeof(struct libnet_udp_hdr);
pck->pl_size = udp_len - sizeof(struct libnet_udp_hdr);

// Set type
pck->m4_type = AO_M4_UDP;
Expand Down
14 changes: 8 additions & 6 deletions src/pk_packet.c
Expand Up @@ -162,21 +162,23 @@ void ao_pck_log(st_ao_packet* pck)
// Layer 4
if ((pck->m4_type == AO_M4_TCP) && (dshow & AO_PROTO_L4_TCP)) {
g_print("* tcp! port_src=%hu, port_dst=%hu, checksum=0x%04x, len=%hu\n",
ntohs(pck->m4.tcp.hdr->source), ntohs(pck->m4.tcp.hdr->dest),
ntohs(pck->m4.tcp.hdr->check), pck->m4.tcp.hdr->doff * 4
ntohs(pck->m4.tcp.hdr->th_sport), ntohs(pck->m4.tcp.hdr->th_dport),
ntohs(pck->m4.tcp.hdr->th_sum), pck->m4.tcp.hdr->th_off * 4
);
g_print("* tcp! res_seq=0x%08x, ack_seq=0x%08x, fin=%u, syn=%u, rst=%u, psh=%u, ack=%u, urg=%u\n", //, ece=%u, cwr=%u
ntohl(pck->m4.tcp.hdr->seq), ntohl(pck->m4.tcp.hdr->ack_seq),
pck->m4.tcp.hdr->fin, pck->m4.tcp.hdr->syn, pck->m4.tcp.hdr->rst, pck->m4.tcp.hdr->psh, pck->m4.tcp.hdr->ack, pck->m4.tcp.hdr->urg
ntohl(pck->m4.tcp.hdr->th_seq), ntohl(pck->m4.tcp.hdr->th_ack),
pck->m4.tcp.hdr->th_flags & TH_FIN, pck->m4.tcp.hdr->th_flags & TH_SYN,
pck->m4.tcp.hdr->th_flags & TH_RST, pck->m4.tcp.hdr->th_flags & TH_PUSH,
pck->m4.tcp.hdr->th_flags & TH_ACK, pck->m4.tcp.hdr->th_flags & TH_URG
//pck->m4.tcp.hdr->ece, pck->m4.tcp.hdr->cwr
);
if (pck->m4.tcp.ts) {
g_print("* tcp! time_a=0x%08x, time_b=0x%08x\n", ntohl(pck->m4.tcp.ts->time_a), ntohl(pck->m4.tcp.ts->time_b));
}
} else if ((pck->m4_type == AO_M4_UDP) && (dshow & AO_PROTO_L4_UDP)) {
g_print("* udp! port_src=%hu, port_dst=%hu, checksum=0x%04x, len=%hu\n",
ntohs(pck->m4.udp.hdr->source), ntohs(pck->m4.udp.hdr->dest),
ntohs(pck->m4.udp.hdr->check), ntohs(pck->m4.udp.hdr->len)
ntohs(pck->m4.udp.hdr->uh_sport), ntohs(pck->m4.udp.hdr->uh_dport),
ntohs(pck->m4.udp.hdr->uh_sum), ntohs(pck->m4.udp.hdr->uh_ulen)
);
}
if ((pck->m4_size > 0) && (
Expand Down
4 changes: 2 additions & 2 deletions src/pk_packet.h
Expand Up @@ -88,11 +88,11 @@ struct t_ao_packet {
// Layer 4
union {
struct {
struct tcphdr* hdr;
struct libnet_tcp_hdr* hdr;
st_tcp_timestamp* ts;
} tcp;
struct {
struct udphdr* hdr;
struct libnet_udp_hdr* hdr;
} udp;
} m4;
guint32 m4_type;
Expand Down

0 comments on commit 8260623

Please sign in to comment.