need help with small git project

Hello,

I need some help with my git project which is a small console program that changes your MAC address for you randomly. At the moment, I need help with 1) How to detect what device they are using either wlan or eth and 2) how to get the output from the console and store it in a string. Also any feedback/criticism is greatly appreciated because I want to be a better programmer :))))).

Project Link: https://github.com/h3y4w/mac-spoof-cpp

Thanks!
Last edited on
1. That depends on what systems calls the OS offers. Do note that a machine can have multiple interface simultaneously active.

2. http://www.cplusplus.com/doc/tutorial/basic_io/


PS. One does need administrative rights to edit MAC on Linux and distros already provide the tools (like udev) to do that.
Thank you for your comment. What I meant by getting output from console is I want to find the home directory of the user so when I run system("whoami"), I can put it in a string. What library would I need to use to do that?

Concerning rights and tools already provided, I am building this for educational purposes to help my programming skills. I thought it would be cool to make my own.
The existing tools are open source. Their code is available. By looking at it you will see what OS functions they do use. It is educational to figure out what and how some third-party code does.
When using system() you can run just about anything as if it were a headless call to bash (non-interactive), you can save the output to a file and read from that (so you could at least get the output from ifconfig and figure out the device name from that)

system(ifconfig > devices.txt);
ifstream file("devices.txt");
file ...read from file... etc.

If you're going to change the mac of one device you might as well change the others at the same time as a precaution. If a device is disabled it will not show up in ifconfig's default output.

You also have to keep in mind that the first half of the mac address (I'll say nic for short) indicates what company produced the device, so it's important that the first half of your "random" mac address corresponds to an existing company...
http://aruljohn.com/mac/vendor/dell <- look up existing vendors like edimax, dell, apple, etc. This link is preset to look up dell
What I did was select a dozen or so of the existing company nic's and saved them in a switch-case form of library so that I could ask for a random number to align to a known company ... You should probably do this separately for ethernet, wifi, and bluetooth.

system(echo ~ > homePath.txt); <- gives you both the username and home directory in one go.
system(pwd >> homePath.txt); <- gives you the current working directory.

As far as security, I would not distribute this kind of code because of all the calls to system(). I couldn't guarantee that the bash interactions would be the same for all systems, and there's no guarantee that someone hasn't replaced one of the programs you are calling with something malicious.

cstdio has the function remove which can then delete the created files for cleanliness... personally, I made a bash script that handled all system calls and my only c++ portion was to simply spit out a valid mac based on the inputs received from argv.

I don't know of a way to output directly to a string from a system call, I checked out your github and agree that python is probably the way to go.

As far as legality, the best I've read is that it is perfectly legal to spoof your mac as long as you don't end up using a nic that is government owned.
Last edited on
Topic archived. No new replies allowed.