Recent

Author Topic: changing my ip address when sending a packet.  (Read 3964 times)

BSaidus

  • Hero Member
  • *****
  • Posts: 540
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
changing my ip address when sending a packet.
« on: October 27, 2018, 08:51:18 pm »
Hello.
I want to know if there is a networking library, that can allow me to specify my origin IP address instead of actual one.
This is for education purpose and not for hacking or ddos attack !!    O:-).
Or can some one point me to a starting point for this task .

Thanks you.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: changing my ip address when sending a packet.
« Reply #1 on: October 28, 2018, 09:32:15 am »
Your true origin IP can be retrieved, but only from an external source afaik. That's why I run ip.thaddy.com and ip.thaddy.com/simple.php
ip.thaddy.com resolves ip including forwarding (the innermost exposed ip) and ip.thaddy.com/simple.php returns the ip without forwarding (the outermost exposed ip).
The returned value is not a html page, but a string that you can immediately use in your sourcecode.
I can do this for other protocols than http(s) too, so can I set it up for email as well. (Basically running a client protocol serverside that analyses full headers, same as I do above, and perform a reverse lookup)
Also note this mechanism does not work for all possible situations. Returning local ip on the network is ofcourse not covered here. That needs to be resolved on network level.

The above enables you to obtain the ip's. You have to enable some passthrough to change the origin IP yourself, which can be done with a reverse proxy for example.

Or do you want to spoof the origin?
See: https://lifehacker.com/how-spammers-spoof-your-email-address-and-how-to-prote-1579478914
You can use both Indy and Synapse for the smtp server code.

Nowadays it is rather futile. I got this at my CEH exams.
« Last Edit: October 28, 2018, 02:42:51 pm by Thaddy »
Specialize a type, not a var.

BSaidus

  • Hero Member
  • *****
  • Posts: 540
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: changing my ip address when sending a packet.
« Reply #2 on: October 30, 2018, 01:44:58 pm »
Thanks,
But what I mean is :
 Before Sending a network packet I want change the header of the PAcket and meanly the origine IP adress of my PC.
 
   ex: if I have my local machine with IP: 192.168.100.5 then before sending a packet I change this IP to : 124.22.254.20

So I wonder if there is a library for FPC or C allowing dowing that.

Thanks
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: changing my ip address when sending a packet.
« Reply #3 on: October 30, 2018, 01:53:17 pm »
As per my link: you can use any of the smtp server components to do that. It is also the only way to do that: Implement the protocol, then add your own spoofed IP instead.
« Last Edit: October 30, 2018, 02:49:07 pm by Thaddy »
Specialize a type, not a var.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: changing my ip address when sending a packet.
« Reply #4 on: October 30, 2018, 03:01:43 pm »
What you want is, basically, what a NAT does, so you may program a "software NAT" and do it. This is not, however, an easy task since it must act at the IP layer (almost) just before sending the packet to the physical layer.

I don't know of any but there may be some package out there that can do that. After all, black-hats and spammers seem to do all the time very easily  :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: changing my ip address when sending a packet.
« Reply #5 on: October 30, 2018, 03:07:53 pm »
What you want is, basically, what a NAT does, so you may program a "software NAT" and do it. This is not, however, an easy task since it must act at the IP layer (almost) just before sending the packet to the physical layer.

I don't know of any but there may be some package out there that can do that. After all, black-hats and spammers seem to do all the time very easily  :)

It is quite easy to do if you control the smtp server. As I explained. NAT does maybe work but still needs to rewrite the headers, which means it must support the smtp protocol, That's the wrong direction.
Much easier to let the smtp server or intermediate server rewrite or write the headers. Again. See my link. I tested it and it is easy, but I won't add code here for obvious reasons: it would be used by script kiddies who can't figure it out for themselves and it is already blatantly easy:
- go to the code that composes the headers
- spoof the IP there
Just one utility function. (or even hard-code the IP like I did in my test)
« Last Edit: October 30, 2018, 03:11:36 pm by Thaddy »
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: changing my ip address when sending a packet.
« Reply #6 on: October 30, 2018, 03:35:51 pm »
Hello.
I want to know if there is a networking library, that can allow me to specify my origin IP address instead of actual one.
This is for education purpose and not for hacking or ddos attack !!    O:-).
Or can some one point me to a starting point for this task .

Thanks you.
To do that you need to use RAW SOCKETS. 

You can find information on how to use raw sockets (presuming you are using Windows):

https://docs.microsoft.com/en-us/windows/desktop/winsock/tcp-ip-raw-sockets-2

Using NAT won't change your IP address.  NAT is used to convert from a non-routable IP to a routable IP (and viceversa).  A private (non routable) IP (assigned by NAT) is associated with a port and sent out the network with the border IP (the routable IP along with the port), when a reply comes back, the NAT layer uses the port to identify the LAN (non routable) IP the packet should locally be routed to.

Using SMTP to change the IP address is simply pure nonsense.  Using the SMTP protocol would enable you to change/spoof the sending email address _not_ the IP address which gets set at a lower level in the TCP/IP stack (Level 3.)

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: changing my ip address when sending a packet.
« Reply #7 on: October 30, 2018, 03:41:34 pm »
Correct, but even when using raw sockets it is detectable in the same way as described in my link.
I stuck to the question and provided info on how to do what he asked. I am sure that is enough.
Specialize a type, not a var.

BSaidus

  • Hero Member
  • *****
  • Posts: 540
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: changing my ip address when sending a packet.
« Reply #8 on: October 30, 2018, 04:19:35 pm »
I see that https://github.com/sam-github/libnet copeled with WinPcap Can do changes of the my original IP with some modifs.

But Libnet can't compiled with gcc  :o.

look :
Code: C  [Select][+][-]
  1. /**
  2.  * Builds a version 4 RFC 791 Internet Protocol (IP) header.
  3.  *
  4.  * @param ip_len total length of the IP packet including all subsequent data (subsequent
  5.  *   data includes any IP options and IP options padding)
  6.  * @param tos type of service bits
  7.  * @param id IP identification number
  8.  * @param frag fragmentation bits and offset
  9.  * @param ttl time to live in the network
  10.  * @param prot upper layer protocol
  11.  * @param sum checksum (0 for libnet to autofill)
  12.  * @param src source IPv4 address (little endian)
  13.  * @param dst destination IPv4 address (little endian)
  14.  * @param payload optional payload or NULL
  15.  * @param payload_s payload length or 0
  16.  * @param l pointer to a libnet context
  17.  * @param ptag protocol tag to modify an existing header, 0 to build a new one
  18.  * @return protocol tag value on success
  19.  * @retval -1 on error
  20.  */
  21. LIBNET_API
  22. libnet_ptag_t
  23. libnet_build_ipv4(uint16_t ip_len, uint8_t tos, uint16_t id, uint16_t frag,
  24. uint8_t ttl, uint8_t prot, uint16_t sum, uint32_t src, uint32_t dst,
  25. const uint8_t* payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag);
  26.  

thanks
« Last Edit: October 30, 2018, 04:22:39 pm by BSaidus »
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018