Join us at IRC!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Thursday, May 24, 2012
Navigation
Members Online
Total Online: 35
Web Spiders: 13
Guests Online: 29
Members Online: 6

Registered Members: 70200
Newest Member: ScubaSteve
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Mac Changer

skathgh420
Member



Posts: 418
Location: 127.0.0.1
Joined: 03.03.08
Rank:
God
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...

#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;
}


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.



1 3 3 www.google.com
Author

RE: Mac Changer

stdio
Member

Posts: 375
Location: omnipresent
Joined: 06.04.08
Rank:
God
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.



I'm sorry, I cant hear you over the sound of how awesome I am!
www.thewebsiteisdown.com
Author

RE: Mac Changer

skathgh420
Member



Posts: 418
Location: 127.0.0.1
Joined: 03.03.08
Rank:
God
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:.


1 3 3 www.google.com
Author

RE: Mac Changer

stdio
Member

Posts: 375
Location: omnipresent
Joined: 06.04.08
Rank:
God
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.



I'm sorry, I cant hear you over the sound of how awesome I am!
www.thewebsiteisdown.com
Author

RE: Mac Changer

COM
Banned



Posts: 800
Location:
Joined: 31.08.07
Rank:
God
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:


...
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.


K'aem'nhi kh'rn, K'aem'nhi kh'r, K'aem'nhi kh'rmnu.
I'a Y'gs-Othoth!

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

RE: Mac Changer

skathgh420
Member



Posts: 418
Location: 127.0.0.1
Joined: 03.03.08
Rank:
God
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:


...
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...

#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 skathgh420 on 15-12-09 07:57
1 3 3 www.google.com
Author

RE: Mac Changer

skathgh420
Member



Posts: 418
Location: 127.0.0.1
Joined: 03.03.08
Rank:
God
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 )


1 3 3 www.google.com
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.