def handle(self, *args, **options): srv = AuthServer(dict = dictionary.Dictionary( "app/radius/dicts/dictionary" )) srv.hosts['192.168.39.211'] = server.RemoteHost('192.168.39.211','hotsp1','hotsp1.it-tim.net') srv.hosts['192.168.70.211'] = server.RemoteHost('192.168.70.211','hotsp2','hotsp2.it-tim.net') srv.hosts['10.11.8.30'] = server.RemoteHost('10.11.8.30','hotsp3','hotsp3.it-tim.net') srv.hosts['192.168.33.33'] = server.RemoteHost('192.168.33.33','thedude','thedude.it-tim.net') srv.hosts['192.168.33.152'] = server.RemoteHost('192.168.33.152','dev','dev.it-tim.net') sleep(5) srv.BindToAddress('192.168.33.70') srv.Run()
def init_hosts(self): for h in self.cfg['settings']['hosts'].keys(): s = self.cfg['settings']['hosts'][h]['secret'] raoklog.info("Intialize host %s with secret `%s'" % (h, s)) self.hosts[h] = server.RemoteHost(h, str(s), "localhost") raoklog.info(" done.")
def __init__(self, config_file): self.config_file = config_file self.config = Config(open(self.config_file, 'r')) hosts = self.config.hosts() self.hosts = { k: server.RemoteHost(v['address'], v['secret'], v['name']) for k, v in hosts.items() }
def AddUser(self, user_address, secret, name=None): """ This method adds the user into RADIUS server user list """ self.hosts[user_address] = server.RemoteHost(user_address, secret, name) self.log.debug("USer %s is added to RADIUS server %s" % (user_address, self.addr))
def AddUser(self, user_address, secret, name=None): """ This method adds the user into RADIUS server user list """ # 33503 - Add secret as a member variable so that it can be # accessed from the testcase self.secret = secret self.hosts[user_address] = server.RemoteHost(user_address, secret, name)
def __init__(self, sql_config, radius_dict): super().__init__(dict=radius_dict) #sets up connection to postresql db self.sql_conn = psycopg2.connect(host=sql_config['address'], dbname=sql_config['dbname'], user=sql_config['user'], password=sql_config['password']) self.hosts["0.0.0.0"] = server.RemoteHost("0.0.0.0", b"secret", "APs") self.BindToAddress("0.0.0.0") self.Run()
def init_hosts(self): for h in self.cfg['settings']['hosts'].keys(): s = self.cfg['settings']['hosts'][h]['secret'] if not Config.SERIOUS: raoklog.info("Initialize host %s with secret `%s'" % (h, s)) else: raoklog.info("Initialize host %s" % (h, )) self.hosts[h] = server.RemoteHost(h, bytes(s, encoding="ascii"), "localhost") raoklog.debug(" done.")
def get_clients(srv): doc = yaml.load( open(os.path.join(os.path.dirname(__file__), "clients", "address.yml"), 'r').read()) for entry in doc: if doc[entry]['type_net'] == "subnet": net = ipaddress.IPv4Network(doc[entry]['IP']) numbers = int(str(net[-1]).split(".")[-1]) - int( str(net[0]).split(".")[-1]) for i in range(0, numbers + 1): srv.hosts[str(net[i])] = server.RemoteHost( str(net[i]), bytes(doc[entry]['secret'], 'utf-8'), doc[entry]['name']) elif doc[entry]['type_net'] == "ip": srv.hosts[doc[entry]['IP']] = server.RemoteHost( doc[entry]['IP'], bytes(doc[entry]['secret'], 'utf-8'), doc[entry]['name']) hostname = socket.gethostname() IPAddr = socket.gethostbyname(hostname) srv.BindToAddress(str(IPAddr)) logging.info("Server listen on IP {}, port 1812".format(str(IPAddr)))
def __init__(self, addresses=[], authport=1812, acctport=1813, coaport=3799, hosts=None, radius_dict=None, auth_enabled=True, acct_enabled=True, coa_enabled=False, net_segment=None, ip_static_file=None): server.Server.__init__(self, addresses, authport, acctport, coaport, hosts, radius_dict, auth_enabled, acct_enabled, coa_enabled) default_hosts = set() default_hosts.add("127.0.0.1") if net_segment is not None: ips = IP(net_segment) for x in ips: default_hosts.add(x.strNormal()) for item in default_hosts: self.hosts[item] = server.RemoteHost(item, self.secret, item) self.ip_static_file = ip_static_file self.clock_stage = dict() self.rs_user_ip = dict() self.clock_interval = 600 self.load_ip_static_file()
def processPacket(self, pkt): super(RADIUSAccountingProtocol, self).processPacket(pkt) if not pkt.VerifyAcctRequest(): raise curved.PacketError('Authentication failed') log.msg("Received {} from {} ({})".format( pkt[b'Acct-Status-Type'][0], pkt.source[0], pkt[b'Acct-Session-Id'][0]) ) reply = self.createReplyPacket(pkt) self.transport.write(reply.ReplyPacket(), reply.source) if __name__ == '__main__': log.startLogging(sys.stdout, 0) reactor.listenUDP(1813, RADIUSAccountingProtocol( hosts={ '192.168.1.11': server.RemoteHost('192.168.1.11', six.b(b'testsecret'), "AP11"), '192.168.1.12': server.RemoteHost('192.168.1.12', six.b(b'testsecret'), "AP12"), }, rad_dict=dictionary.Dictionary('dictionary')) ) reactor.run()
print("Attributes: ") for attr in pkt.keys(): print("%s: %s" % (attr, pkt[attr])) reply = self.CreateReplyPacket(pkt) self.SendReplyPacket(pkt.fd, reply) def HandleDisconnectPacket(self, pkt): print("Received an disconnect request") print("Attributes: ") for attr in pkt.keys(): print("%s: %s" % (attr, pkt[attr])) reply = self.CreateReplyPacket(pkt) # COA NAK reply.code = 45 self.SendReplyPacket(pkt.fd, reply) if __name__ == '__main__': # create server and read dictionary srv = FakeServer(dict=dictionary.Dictionary("dictionary"), coa_enabled=True) # add clients (address, secret, name) srv.hosts["127.0.0.1"] = server.RemoteHost("127.0.0.1", b"Kah3choteereethiejeimaeziecumi", "localhost") srv.BindToAddress("0.0.0.0") # start server srv.Run()
""" # RCS filename: $RCSfile$ # Author: $Author: root $ # File version: $Revision: 75 $ # Last changes (GMT): $Date: 2005-11-29 21:56:55 +0200 (Ot, 29 Nov 2005) $ # Branch (or tag): $Name$ # import modules import sys sys.path.insert(0, './lib') from pyrad import server, dictionary # bsdradius modules import BsdRadiusServer print "Starting server" dict = dictionary.Dictionary( '/usr/home/valdiic/dev/bsdradius/dictionaries/dictionary') #sys.exit(0) srv = BsdRadiusServer.BsdRadiusServer(dict=dict) # add valid server client hosts srv.hosts["127.0.0.1"] = server.RemoteHost("127.0.0.1", "testing123", "localhost") # bind to all IP addresses srv.BindToAddress("") # run server srv.Run()
print("Attributes: ") for attr in pkt.keys(): print("%s: %s" % (attr, pkt[attr])) reply = self.CreateReplyPacket(pkt) self.SendReplyPacket(pkt.fd, reply) def HandleDisconnectPacket(self, pkt): print("Received an disconnect request") print("Attributes: ") for attr in pkt.keys(): print("%s: %s" % (attr, pkt[attr])) reply = self.CreateReplyPacket(pkt) # COA NAK reply.code = 45 self.SendReplyPacket(pkt.fd, reply) if __name__ == '__main__': # create server and read dictionary srv = pfsense_radius(dict=dictionary.Dictionary("dictionary")) #Accept from any client but has to have the secret. Cant add specific host right now without modifying back server.py in pyrad srv.hosts["0.0.0.0/0"] = server.RemoteHost("0.0.0.0/0", b"somesecretvalue", "0.0.0.0/0") srv.BindToAddress("") # start server srv.Run()
upload) except (urllib2.URLError, urllib2.HTTPError), e: if hasattr(e, 'code') and e.code == 404: reply.code = packet.AccessReject print "reject: %s" % mac_address else: if mac_address in member_cache: reply.AddAttribute((14122, 8), '0') reply.AddAttribute((14122, 7), '0') print "accept [failover]: %s %s" % ( mac_address, member_cache[mac_address]) else: print "accept [failover]: %s" % mac_address reply.code = packet.AccessAccept self.SendReplyPacket(pkt.fd, reply) thread = threading.Thread(target=_handle) thread.start() srv = RadiusServer(addresses=[''], dict=dictionary.Dictionary("dictionary")) srv.hosts["192.168.1.1"] = server.RemoteHost("192.168.1.1", "secret", "localhost") logger.info("starting server...") try: srv.Run() except KeyboardInterrupt: sys.exit(0)
reply = self.CreateReplyPacket(pkt) self.SendReplyPacket(pkt.fd, reply) def HandleDisconnectPacket(self, pkt): print("Received an disconnect request") print("Attributes: ") for attr in pkt.keys(): print("%s: %s" % (attr, pkt[attr])) reply = self.CreateReplyPacket(pkt) # COA NAK reply.code = 45 self.SendReplyPacket(pkt.fd, reply) if __name__ == '__main__': # create server and read dictionary srv = FakeServer( dict=dictionary.Dictionary("/opt/pi-disco/agents/dictionary"), coa_enabled=True) # add clients (address, secret, name) srv.hosts["EX_IP"] = server.RemoteHost("EX_IP", b"EX_SECRET", "EXSWITCH") srv.BindToAddress("") # start server srv.Run()
print("%s: %s" % (attr, pkt[attr])) reply = self.CreateReplyPacket( pkt, **{ "Service-Type": "Framed-User", "Framed-IP-Address": '192.168.0.1', "Framed-IPv6-Prefix": "fc66::1/64" }) reply = clt.SendPacket(pkt) newreply = self.CreateReplyPacket(pkt) for attr in reply.keys(): newreply.AddAttribute(attr, reply[attr]) newreply.code = reply.code self.SendReplyPacket(pkt.fd, newreply) return if __name__ == '__main__': # create server and read dictionary srv = FakeProxy(dict=dictionary.Dictionary("dictionary"), coa_enabled=True) # add clients (address, secret, name) srv.hosts["0.0.0.0"] = server.RemoteHost("0.0.0.0", b"testing123", "localhost") srv.BindToAddress("0.0.0.0") # start server srv.Run()
#!/usr/bin/python #-*- coding: utf-8 -*- import config from pyrad import dictionary from pyrad import server import sqlite_server from auth_server import AuthServ __author__ = "jely_scs" __version__ = 1.0 # main print "Check SQLite" sqlite = sqlite_server.SQLite_srv() print "Start radius server" srv = AuthServ( dict=dictionary.Dictionary("conf/dictionary.bak"), authport=config.radius_auth_port, ) srv.sqlite_srv = sqlite srv.hosts["127.0.0.1"] = server.RemoteHost("127.0.0.1", config.secret, "localhost") srv.BindToAddress(config.radius_bind_to_address) srv.Run() print "Stop server"
class TestServer(server.Server): def _HandleAuthPacket(self, pkt): server.Server._HandleAuthPacket(self, pkt) passwd = [] for key in pkt.keys(): if key == "User-Password": passwd = map(pkt.PwDecrypt, pkt[key]) reply = self.CreateReplyPacket(pkt) if passwd == ['accept']: reply.code = packet.AccessAccept else: reply.code = packet.AccessReject self.SendReplyPacket(pkt.fd, reply) srv = TestServer( addresses=["localhost"], hosts={"127.0.0.1": server.RemoteHost("127.0.0.1", "foo", "localhost")}, dict=dictionary.Dictionary(StringIO.StringIO(DICTIONARY))) # Write a sentinel character to let the parent process know we're listening. sys.stdout.write("~") sys.stdout.flush() srv.Run()
def runServer(): srv = GuestServer(addresses=['0.0.0.0'], dict=dictionary.Dictionary("dictionary")) srv.hosts["127.0.0.1"] = server.RemoteHost("127.0.0.1", SHARED_SECRET, "localhost") srv.hosts["192.168.1.1"] = server.RemoteHost("192.168.1.1", SHARED_SECRET, "pfsense") srv.Run()