Python: Add Promiscuous Mode To Interface

So.. I started programming in python this weekend. I’ve touched on it before but never really gave it a fair chance. I was looking for a while on how to set an interface into promiscuous mode for some arp spoofing tool that i’m creating and while searching couldn’t really find anything….

so here is my little snippet for anyone looking to do the same thing:

import socket;
import struct;
import fcntl;

SIOCGIFFLAGS = 0x8913;
SIOCSIFFLAGS = 0x8914;
IFF_PROMISC = 0x100;

current_flags = 0;

sd = socket.socket(socket.PF_PACKET, socket.SOCK_RAW);

# This will return the current flags present on the interface
ifreq = fcntl.ioctl(sd, SIOCGIFFLAGS, “eth0” + “” * 256);

# extract current flags field from struct returned
(current_flags,) = struct.unpack(“16xH”, ifreq[:18]);

# add the Promisc flag
current_flags |= IFF_PROMISC;

# create the new struct for setting the interface flags
ifreq = struct.pack(“4s12xH”, “eth0”, current_flags);

# call ioctl() to update the flags for the interface
fcntl.ioctl(sd, SIOCSIFFLAGS, ifreq);

# Turn off the IFF_PROMISC flag
current_flags ^= IFF_PROMISC;
ifreq = struct.pack(“4s12xH”, “eth0”, current_flags);

# remove the Promisc flag from the interface once done
fcntl.ioctl(sd, SIOCSIFFLAGS, ifreq);

If you think of any other ways to do the above in a more ‘clean’ format, please leave a comment as I would love to know how.

Advertisements

MySQL ROOT Password Reset

I have just lost my root password for mysql (stupid me). Thankfully I came across this little tidbit to allow resurrection of my server..

1) As root, stop the MySQL daemon (example: service mysqld stop)

2) Start MySQL via

mysqld_safe --skip-grant-tables &

3) Connect to MySQL via

mysql -u root

4) Run the following

use mysql;
update user set password=PASSWORD("yournewpassword") where User='root';
flush privileges;

5) Kill mysqld_safe and restart MySQL normally (example: service mysqld start)

Credit to: http://www.whatsmypass.com/mysql-password-reset

Microsoft Lawsuit

Well.. after the aftermath of the xbox banning on November 3rd, it seems that people are toying with the idea of a lawsuit against Microsoft.

I wish them the best of luck. I in part agree with Microsoft’s decision to ban modded Xbox’s from using the Xbox Live service but unfortunately they didn’t stop there. Revoking the Xbox ID so that the Xbox is unable to save games should not be allowed. The best analogy I can come up with is… if you modded your toaster so that it cooked your bread quicker, would you allow the manufacturer to come to your house and smash your toaster with a hammer, because that’s effectively what Microsoft have done.

For more information: http://www.abingtonlaw.com/Xbox-Live-class-action.html