3

Well, I know its possible, using external libraries and modules such as scapy. But how about without external modules? Without running the script as root? No external dependencies?

I've been doing a lot of googling, but haven't found much help. I'd like to be able to create my own packets, but without running as root, or installing extra dependencies.

Any suggestions?

Rob
  • 7,980
  • 30
  • 75
  • 115
  • You can create all the raw packets you want, but you won't be able to send them anywhere unless you're root. Also, of course you can write them without external modules - external modules are written in the same Python that you'll write your code in, you'll just be reinventing the wheel. – Nick Bastin May 16 '10 at 05:09
  • What kind of packets do you want to craft? – Daniel Stutzbach May 16 '10 at 14:16
  • Hand-crafted SYN packets always require root. There's no way around that. Opening a TCP connection will send a SYN packet, so I suppose you could open and close many TCP connections but you won't have a lot of control over the SYN packets' contents and you won't be able to send them as fast. – Daniel Stutzbach May 17 '10 at 13:35

2 Answers2

2

Here's how to code raw ICMP "ping" packets in Python:

http://www.g-loaded.eu/2009/10/30/python-ping/

johntellsall
  • 14,394
  • 4
  • 46
  • 40
1

Many operating systems (Linux) do not allow raw sockets unless your effective user ID is 0 (aka root). This isn't a library issue. Some operating systems (non-server Windows post Windows XP SP2) do not allow crafting raw sockets period.

You can read more about raw sockets by man 7 raw on your system. Note that the socket options can all be passed using the Python socket module.

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82