Packet packet = ip_header / udp_header / dns_header;
Packet packet = ether_header / ip_header / udp_header / dns_header;The only problem is that you will need to craft the ethernet header by setting the destination MAC addresses. You can use libcrafter to so that also. The full code will be :
#include <iostream>
#include <string>
#include <crafter.h>
/* Collapse namespaces */
using namespace std;
using namespace Crafter;
int main() {
/* Set the interface */
string iface = "wlan0";
/* Get the IP address associated to the interface */
string MyIP = GetMyIP(iface);
string dns_server = "192.168.0.1";
/* Create Ethernet layer */
Ethernet ether_header;
ether_header.SetSourceMAC(GetMyMAC(iface));
ether_header.SetDestinationMAC(GetMAC(dns_server, iface));
/* Create an IP header */
IP ip_header;
/* Set the Source and Destination IP address */
ip_header.SetSourceIP(MyIP);
ip_header.SetDestinationIP(dns_server);
ip_header.SetDiffServicesCP(0x04);
/* Create a UDP header */
UDP udp_header;
/* Set the source and destination ports */
udp_header.SetSrcPort(RNG16());
udp_header.SetDstPort(53);
/* Create a DNS layer */
DNS dns_header;
/* Set a random ID */
dns_header.SetIdentification(RNG16());
/* Create a DNSQuery class. This class IS NOT a <Layer> class */
DNS::DNSQuery dns_query("www.google.com");
/* Set the type */
dns_query.SetType(DNS::TypeA);
/* Push the query into a container inside the DNS header */
dns_header.Queries.push_back(dns_query);
/* Create a packet... */
Packet packet = ether_header / ip_header / udp_header / dns_header;
/* Send and wait for an answer */
Packet* rcv = packet.SendRecv(iface);
if(rcv) {
/*
* An application protocol is always get from the network as a raw layer. There is
* no way to know which protocol is on the top of a transport layer (unless we rely on
* standard ports numbers, which is not always the case).
*/
DNS dns_rcv;
/* Fill the DNS layer information from a raw layer */
dns_rcv.FromRaw(*(rcv->GetLayer<RawLayer>()));
/* Finally print the response to STDOUT */
dns_rcv.Print();
/* Delete the received packet */
delete rcv;
} else
cout << "[@] No response from DNS server" << endl;
return 0;
}
--
You received this message because you are subscribed to the Google Groups "libcrafter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libcrafter+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.