How can I spoof the sender IP address using curl? How can I spoof the sender IP address using curl? unix unix

How can I spoof the sender IP address using curl?


For my own purposes, changing the HTTP header was enough, via the following:

curl --header "X-Forwarded-For: 1.2.3.4" "http://www.foobar.com"


You can't.

In general, spoofing IP addresses for TCP is remarkably difficult. Unless you have control of a router quite near your target or near the IP you're spoofing, consider it impossible.

The reply packets need a path back to you in order to complete even the three-way handshake. The most reliable way to do this is to have control over a router in the most common pathway between your target and your spoofed IP address: this would let you capture packets between the target and the spoofed address and forward them on to you.

You could also try injecting bogus BGP route advertisements, but doing so would doubtless be noticed and cost you dearly when your peers drop you completely.


Can I make libcurl fake or hide my real IP address?

No. libcurl operates on a higher level. Besides, faking IP address would imply sending IP packet with a made-up source address, and then you normally get a problem with receiving the packet sent back as they would then not be routed to you!

If you use a proxy to access remote sites, the sites will not see your local IP address but instead the address of the proxy.

Also note that on many networks NATs or other IP-munging techniques are used that makes you see and use a different IP address locally than what the remote server will see you coming from.