Follow us on Twitter!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Saturday, April 19, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 30
Guests Online: 29
Members Online: 1

Registered Members: 82835
Newest Member: phanton2043
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 06:35
I just finished writing a little app in C to change my mac address to something random every time it is run.

Here is the source code for it...

Code
#include <time.h>
#include <stdio.h>
#include <unistd.h>

int main()

  char mac[100]; 
  time_t seconds;
  time(&seconds);
  srand((unsigned int) seconds);
 
  sprintf(mac, "00:%d:%d:%d:%d:%d",rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10);
 
  char* cmd[] = { "ifconfig", "wlan0", "down", "hw", "ether", mac, NULL };
  char* cmd2[] = { "ifconfig", "wlan0", "up", NULL };
 
  pid_t pID = fork();
 
  if(pID < 0)        // <-- fail
  {
    return 0;
  }
  else if(pID == 0)  // <-- child
  {
    execvp("ifconfig", cmd);
    execvp("ifconfig", cmd2);
    return 0;
  }
  else               // <-- parent
  {
    return 0;
  }
 
  return 0;
}





Code
root@Th3r00t0r:~/code# gcc -o mac mac.c
root@Th3r00t0r:~/code# ./mac
root@Th3r00t0r:~/code# ifconfig -a | grep wlan0
wlan0     Link encap:Ethernet  HWaddr 00:49:60:58:46:18 
root@Th3r00t0r:~/code# ./mac
root@Th3r00t0r:~/code# ifconfig -a | grep wlan0
wlan0     Link encap:Ethernet  HWaddr 00:78:96:41:68:61 
root@Th3r00t0r:~/code# ./mac
root@Th3r00t0r:~/code# ifconfig -a | grep wlan0
wlan0     Link encap:Ethernet  HWaddr 00:69:52:11:51:10





It works fine so I put the path to the binary/executable in /etc/rc.local and every time i restart my laptop
my mac is something different so that worked too. I just have two little questions.

1. From my reading all programs ran from /etc/rc.local must always return 0 or exit 0. That's why I have four return 0 statements in my code. It was a precautionary measure to not mess anything up on start-up and execution of the app (just in case something went wrong). I think though (and this is what I am asking) that all those return 0 statements aren't necessary but i just don't know which one(s) should be removed.

2. Every time I start my laptop my mac address is different, and that's great. The thing is though at a couple of places my laptop auto connects to wireless networks at start-up as well. Will the app in /etc/rc.local execute and change my mac address before my laptop auto connects to the wireless access point? I would just test this myself but untill three day's from now I wont be able to test this on my own wireless network to see the mac address of people connecting.

Thanks a bunch for any an all help :D.



Author

RE: Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 06:46
Ill help with question 2:

It really depends on how your computer is set up.

Ive had my dhcp configured in my /etc/conf.d/net and set it to connect at boot time with predetermined networks. In this scenario it would probably happen before you ran your program.

However if you have a wicd for example auto connect after your desktop is loaded then no it would happen after.

These are just two examples of where it could go either way. So its really how you want to set it up.


Author

RE: Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 06:55
stdio wrote:
However if you have a wicd for example auto connect after your desktop is loaded then no it would happen after.


Cool that seems like a really nice open source app. Will definitely check that out. Sounds perfect for
what I am trying to accomplish here. Thanks a bunch for sharing :happy:.


Author

RE: Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 07:06
Yeah I like wicd as its not very resource dependent. Though the version I have current hates essid's of numbers and hangs with auto-connecting. Fuckers. Still better than networkmanager with nm-applet and its 50 gnome libraries that go with it.


Author

RE: Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 07:09
Remove the if and the else statement and make "else if" just an if while removing the return 0 in it.
As in:

Code

...
pid_t pID = fork();

if(pID == 0) // <-- child
{
execvp("ifconfig", cmd);
execvp("ifconfig", cmd2);
}

return 0;
}





Edit: in fact, with this you shouldn't even have to assign the returned value of fork() as it will suffice to call it at the check in the if statement.




Edited by on 15-12-09 07:14
Author

RE: Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 07:20
COM wrote:
Remove the if and the else statement and make "else if" just an if while removing the return 0 in it.
As in:

Code

...
pid_t pID = fork();

if(pID == 0) // <-- child
{
execvp("ifconfig", cmd);
execvp("ifconfig", cmd2);
}

return 0;
}





Thanks COM was hoping you'd have some programming insight to clear that up. I guess i misunderstood the fork()ing process a bit. If fork() did fail the main() return 0 would cover it and I'm guessing when the parent process returns 0 the child process returns 0 as well. That is why the else return 0 iwas not needed.

Code edited...

Code
#include <time.h>
#include <stdio.h>
#include <unistd.h>

int main()
{
    char mac[100];
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);

    sprintf(mac, "00:%d:%d:%d:%d:%d",rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10,rand()%(99-10)+10);

   char* cmd[] = { "ifconfig", "wlan0", "down", "hw", "ether", mac, NULL };
   char* cmd2[] = { "ifconfig", "wlan0", "up", NULL };

   if(fork() == 0) // <-- child
   {
       execvp("ifconfig", cmd);
       execvp("ifconfig", cmd2);
   }
   return 0;
}





Thanks for the help ^_^




Edited by on 15-12-09 07:57
Author

RE: Mac Changer


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 15-12-09 09:14
stdio wrote:
Yeah I like wicd as its not very resource dependent. Though the version I have current hates essid's of numbers and hangs with auto-connecting. Fuckers. Still better than networkmanager with nm-applet and its 50 gnome libraries that go with it.


I don't know if this is related but EVERY machine/os/lappy I've been on has had trouble with this one BSSID not the essid (almost the same thang). When I look at all the open wireless connections its like gibberish, null characters, random characters, and the like. When said network tries to get owned it wont work...... I have the most strife-ling assumption it has to do with the fact that the bssid is ridiculous. It is a WEP encrypted connection, SO seriously it should just be another pwn but.. Its not the bssid fucks it up. Is there any way around this? exmple bssid output: ( will give to you tomorrow due to an insufficiency of wifi connection )