lano
Aktives Mitglied
Moin.
Ich hab da nen Problem. Ich will nen Beacon senden um nen fake accesspoint zu basteln.
Jetzt scheitert das schon an den blöden speichergeschichten.
Ich raff es einfach nicht.
Hier ma der Code:
Hauptproblem ist das verständniss bei FixedParameter und die TaggedParameter_00 und TaggedParameter_01.
Ich raff das einfach nicht mit dem dämlichen Speicher. Nach meiner logic sieht das gut aus.
Nur wird nicht das in die Luft gejagt was ich eigentlich gedacht hätte.
Jemand ne Idee ?
Ich hab da nen Problem. Ich will nen Beacon senden um nen fake accesspoint zu basteln.
Jetzt scheitert das schon an den blöden speichergeschichten.
Ich raff es einfach nicht.
Hier ma der Code:
C:
#include <arpa/inet.h>
#include <errno.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Defined in include/linux/ieee80211.h */
struct ieee80211_hdr {
uint16_t /*__le16*/ frame_control;
uint16_t /*__le16*/ duration_id;
uint8_t addr1[6];
uint8_t addr2[6];
uint8_t addr3[6];
uint16_t /*__le16*/ seq_ctrl;
} __attribute__((packed));
#define WLAN_FC_TYPE_DATA 0
#define WLAN_FC_SUBTYPE_DATA 8
/*************************** START READING AGAIN ******************************/
/* A bogus MAC address just to show that it can be done */
const uint8_t mac1[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; /* Destination */
const uint8_t mac2[6] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab}; /* Source */
const uint8_t mac3[6] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xac}; /* BSSID */
static const uint8_t u8aRadiotapHeader[] = {
0x00,
0x00, // radiotap version
0x18,
0x00, // number of bytes in our header
0x0f,
0x80,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00, // <-- timestamp
/**
* This is the first set of flags, and we've set the bit corresponding to
* IEEE80211_RADIOTAP_F_FCS, meaning we want the card to add a FCS at the end
* of our buffer for us.
*/
0x10,
0x00, // rate
0x00,
0x00,
0x00,
0x00, // channel
0x08,
0x00,
};
static const uint8_t u8aFixedParameters[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Timestamp
0x00, 0x64, // Beacon Interval
0x31, 0x10, // Capabilities Information
};
static const uint8_t u8aTaggedParameter_00[] = {
0x00, //Tag Number
0x05, // Tag length
0x58, 0x2d, 0x4d, 0x41, 0x53, //SSID
};
static const uint8_t u8aTaggedParameter_01[] = {
0x01, //Tag Number
0x08, // Tag length
0x82, 0x84, 0x8b, 0x96, 0x8c, 0x12, 0x98, 0x24,
};
int msleep(long msec);
int main(void) {
/* The parts of our packet */
uint8_t *rt; /* radiotap */
struct ieee80211_hdr *hdr;
uint8_t *FixedParameter;
uint8_t *TaggedParameter_00;
uint8_t *TaggedParameter_01;
/* Other useful bits */
uint8_t *buf;
size_t sz;
uint8_t fcchunk[2]; /* 802.11 header frame control */
/* PCAP vars */
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *ppcap;
/* Total buffer size (note the 0 bytes of data and the 4 bytes of FCS */
sz = sizeof(u8aRadiotapHeader) + sizeof(struct ieee80211_hdr) + (sizeof(u8aFixedParameters)) + (sizeof(u8aTaggedParameter_00)) + (sizeof(u8aTaggedParameter_01)) + 4; /* FCS */
buf = (uint8_t *)malloc(sz);
/* Put our pointers in the right place */
rt = (uint8_t *)buf;
hdr = (struct ieee80211_hdr *)(rt + sizeof(u8aRadiotapHeader));
FixedParameter = (uint8_t *)(hdr + 1);
TaggedParameter_00 = (uint8_t *)(FixedParameter + 1);
TaggedParameter_01 = (uint8_t *)(TaggedParameter_00 + 1);
/* The radiotap header */
memcpy(rt, u8aRadiotapHeader, sizeof(u8aRadiotapHeader));
fcchunk[0] = ((WLAN_FC_TYPE_DATA << 2) | (WLAN_FC_SUBTYPE_DATA << 4));
fcchunk[1] = 0x02;
memcpy(&hdr->frame_control, &fcchunk[0], 2 * sizeof(uint8_t));
hdr->duration_id = 0xffff;
memcpy(&hdr->addr1[0], mac1, 6 * sizeof(uint8_t));
memcpy(&hdr->addr2[0], mac2, 6 * sizeof(uint8_t));
memcpy(&hdr->addr3[0], mac3, 6 * sizeof(uint8_t));
hdr->seq_ctrl = 0;
memcpy(FixedParameter, u8aFixedParameters, sizeof(u8aFixedParameters));
//Tag: SSID parameter
memcpy(TaggedParameter_00, u8aTaggedParameter_00, sizeof(u8aTaggedParameter_00));
// Tag: Supported Rates
memcpy(TaggedParameter_01, u8aTaggedParameter_01, sizeof(u8aTaggedParameter_01));
/**
* Finally, we have the packet and are ready to inject it.
* First, we open the interface we want to inject on using pcap.
*/
ppcap = pcap_open_live("wlp1s0mon", 800, 1, 20, errbuf);
if (ppcap == NULL) {
printf("Could not open interface wlp1s0mon for packet injection: %s", errbuf);
return 2;
}
for (int i = 0; i <= 100; i++) {
if (pcap_sendpacket(ppcap, buf, sz) == 0) {
// pcap_close(ppcap);
// return 0;
}
msleep(100);
}
pcap_perror(ppcap, "Failed to inject packet");
pcap_close(ppcap);
return 1;
}
int msleep(long msec) {
struct timespec ts;
int res;
if (msec < 0) {
errno = EINVAL;
return -1;
}
ts.tv_sec = msec / 1000;
ts.tv_nsec = (msec % 1000) * 1000000;
do {
res = nanosleep(&ts, &ts);
} while (res && errno == EINTR);
return res;
}
Hauptproblem ist das verständniss bei FixedParameter und die TaggedParameter_00 und TaggedParameter_01.
Ich raff das einfach nicht mit dem dämlichen Speicher. Nach meiner logic sieht das gut aus.
Nur wird nicht das in die Luft gejagt was ich eigentlich gedacht hätte.
Jemand ne Idee ?