diff options
Diffstat (limited to 'kpov_judge/tasks/radius_mysql_pam')
-rw-r--r-- | kpov_judge/tasks/radius_mysql_pam/task.py | 102 |
1 files changed, 60 insertions, 42 deletions
diff --git a/kpov_judge/tasks/radius_mysql_pam/task.py b/kpov_judge/tasks/radius_mysql_pam/task.py index 49df48a..3bdcc12 100644 --- a/kpov_judge/tasks/radius_mysql_pam/task.py +++ b/kpov_judge/tasks/radius_mysql_pam/task.py @@ -5,19 +5,21 @@ instructions = {
'si':u"""
Ustvari dva navidezna računalnika - SimpleArbiter z diska simpleArbiterDhcp ter
-RadiusServer. SimpleArbeiterDhcp dobis na naslovu polz.si/media/uploads/kpov/virtualke. Na RadiusServer namesti OpenRadius. Dodatna navodila za instalacijo najdete na evbergen.home.xs4all.nl/openradius/doc-using-openradius.html.OpenRadius uporablja dve konfiguracijski datoteki. To sta /etc/openradius/configuration in /etc/openradius/behaviour.
-Prejsnja definira serverjeve vire in vmesnike slednja pa nastavi, kako bo server delal z zahtevami. Na SimpleArbiter preberi uporabnisko ime in geslo
-uporabnika ter ga dodaj v konfiguracijo FreeRadius na RadiusServer. Na SimpleArbiter
-preberi skrivnost ter poskrbi, da se bo s to skrivnostjo SimpleArbiter lahko povezal
-na RadiusServer.
+RadiusServer. SimpleArbeiterDhcp dobis na naslovu polz.si/media/uploads/kpov/virtualke. Na RadiusServer namesti FreeRadius.
+Na SimpleArbiter preberi skrivnost ter poskrbi, da se bo s to skrivnostjo SimpleArbiter lahko povezal na RadiusServer.
-Nato na OpenRadius namesti še podatkovno bazo mysql. Na SimpleArbiter preberi še ime podatkovne baze,
-uporabniško ime na bazi ter geslo, s katerim se bo lahko klient s SimpleArbiter na to bazo lahko povezal.
-Ustvari podatkovno bazo.Najprej namestimo mysql server. Nato se prijavimo v Mysql server z ukazom mysql -u root -p. Bazo ustvarimo z ukazom CREATE DATABASE <imePodatkovneBaze>. V bazi ustvari tabelo "users" s stolpcema username ter password.
-Na RadiusServer ustvari uporabnika test. Nastavi PAM tako, da se bo geslo uporabnika primerjalo z vnosom
-v tabeli v mysql, namesto da se uporabi datoteka /etc/passwd oziroma /etc/shadow.
+Nato na RadiusServer namesti še podatkovno bazo mysql. Na SimpleArbiter preberi ime podatkovne baze, uporabniško ime na bazi ter geslo, s katerim se bo lahko klient s SimpleArbiter na to bazo lahko povezal.
+
+V bazi ustvari tabele, potrebne za delovanje FreeRadius (več na http://wiki.freeradius.org/guide/SQL-HOWTO). Nastavi FreeRadius tako, da se bodo podatki o uporabnikih črpali iz baze mysql.
+
+Na SimpleArbiter preberi uporabnisko ime in geslo
+uporabnika ter ga dodaj v mysql tako, da bo strežnik Radius uporabnika s tem geslom sprejel. Za uporabnika ustvari tudi uporabniški račun (npr. z ukazom adduser). Upoštevaj, da testni program lahko temu uporabniku spremeni geslo. Poleg tega naj še vedno deluje prijava z uporabniškim imenom student in geslom vaje.
+
+Nastavi PAM za prijavo (login) tako, da bo dovolj, če se uporabnik na ssh predstavi z geslom na strežniku Radius, ne glede na vnos v /etc/passwd oziroma /etc/shadow.
""",
- 'en':u"""Create two virtual computers - SimpleArbiter (using the SimpleArbiterDhcp.vdi disk) and RadiusServer. You can get the disk image at polz.si/media/uploads/kpov/virtualke. Install OpenRadius on the RadiusServer VM. Installation instructions can be found at evbergen.home.xs4all.nl/openradius/doc-using-openradius.html. OpenRadius uses two configuration files /etc/openradius/configuration and /etc/openradius/behaviour. The first one defines sources and interfaces of the server, the second one defines how the server responds to requests. Add your username and password from the SimpleArbiter VM to the OpenRadius configuration. Make shure that SimpleArbiter is able to connect to RadiusServer using the shared secret.
+ 'en':u"""
+TODO: correct this.
+Create two virtual computers - SimpleArbiter (using the SimpleArbiterDhcp.vdi disk) and RadiusServer. You can get the disk image at polz.si/media/uploads/kpov/virtualke. Install OpenRadius on the RadiusServer VM. Installation instructions can be found at evbergen.home.xs4all.nl/openradius/doc-using-openradius.html. OpenRadius uses two configuration files /etc/openradius/configuration and /etc/openradius/behaviour. The first one defines sources and interfaces of the server, the second one defines how the server responds to requests. Add your username and password from the SimpleArbiter VM to the OpenRadius configuration. Make shure that SimpleArbiter is able to connect to RadiusServer using the shared secret.
Install the MySQL database on the RadiusServer VM. Log into the MySQL server using mysql -u root -p . Create the database using CREATE DATABASE <dbnamehere>. Add the columns username and password. Create the user test on RadiusServer and setup PAM so that the user password is checked against the MySQL database instead of the file /etc/passwd or /etc/shadow.
"""
}
@@ -58,54 +60,70 @@ computers = { networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
params_meta = {
- 'IP_RS': {'descriptions': {'si': 'Naslov RadiusServer'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_RS': {'descriptions': {'si': 'Naslov RadiusServer'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False},
'RADIUS_SECRET':{'descriptions': {'si': 'Skrivnost RADIUS'}, 'w': False, 'public':True, 'type': 'password', 'generated': True},
- 'RADIUS_USERNAME': {'descriptions': {'si': 'Username v RADIUS'}, 'w': True, 'public':True, 'type': 'username', 'generated': False},
- 'RADIUS_PASSWORD': {'descriptions': {'si': 'Geslo v RADIUS'}, 'w': False, 'public':True, 'type': None, 'generated': True},
- 'MYSQL_DB_NAME': {'descriptions': {'si': 'Ime baze v mysql'}, 'w': True, 'public':True, 'type': None, 'generated': False},
- 'MYSQL_ADMIN_USER':{'descriptions': {'si': 'Username za dostop do MySQL'}, 'w': True, 'public':True, 'type': 'username', 'generated': False},
+ 'RADIUS_USERNAME': {'descriptions': {'si': 'Uporabniško ime'}, 'w': True, 'public':True, 'type': 'username', 'generated': False},
+ 'RADIUS_PASSWORD': {'descriptions': {'si': 'geslo uporabnika'}, 'w': False, 'public':True, 'type': None, 'generated': True},
+ 'MYSQL_DB_NAME': {'descriptions': {'si': 'Ime baze v mysql'}, 'w': False, 'public':True, 'type': None, 'generated': True},
+ 'MYSQL_ADMIN_USER':{'descriptions': {'si': 'Uporabniško ime za dostop do MySQL'}, 'w': False, 'public':True, 'type': 'username', 'generated': True},
'MYSQL_ADMIN_PASSWORD': {'descriptions': {'si': 'Geslo za dostop do MySQL'}, 'w': True, 'public':True, 'type': 'password', 'generated': True},
- 'MYSQL_TEST_USER':{'descriptions': {'si': 'Username za testiranje PAM'}, 'w': False, 'public':False, 'type': 'username', 'generated': True},
- 'MYSQL_TEST_PASSWORD': {'descriptions': {'si': 'Geslo za testiranje PAM'}, 'w': False, 'public':False, 'type': 'password', 'generated': True},
- 'MYSQL_PAM_USERNAME': {'descriptions': {'si': 'Username v MySQL'}, 'w': True, 'public': True, 'type': 'username', 'generated': False},
- 'MYSQL_PAM_PASSWORD': {'descriptions': {'si': 'Geslo za uporabnika v MySQL'}, 'w': True, 'public': True, 'type': 'password', 'generated': False},
+ 'MYSQL_SEED':{'descriptions': {'si': 'seed'}, 'w': False, 'public':True, 'type': None, 'generated': True},
}
-def task(IP_RS, RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, MYSQL_ADMIN_USER, MYSQL_ADMIN_PASSWORD, MYSQL_TEST_USER, MYSQL_TEST_PASSWORD, MYSQL_PAM_USERNAME, MYSQL_PAM_PASSWORD, MYSQL_DB_NAME):
+def task(IP_RS, RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, MYSQL_DB_NAME, MYSQL_ADMIN_USER, MYSQL_ADMIN_PASSWORD, MYSQL_SEED):
import pxssh
+ import pexpect
+ import random
results = dict()
peer_user = 'student'
peer_passwd = 'vaje'
-
- sR = pxssh.pxssh()
- sR.login(IP_RS, peer_user, peer_passwd)
-
+ r = random.Random(MYSQL_SEED)
+ MYSQL_TEST_USER = kpov_random_helpers.username_gen(r)
+ MYSQL_TEST_PASSWORD = kpov_random_helpers.alnum_gen(r, 7)
+ RADIUS_NEW_PASSWORD = kpov_random_helpers.alnum_gen(r, 7)
# Testiranje radius strtežnika
- results['Test_RadiusServer'] = sR.run('radtest {0} {1} {3} 1812 {4}'.format(
- RADIUS_USERNAME, RADIUS_USERNAME,
- RADIUS_PASSWORD, IP_RS, RADIUS_SECRET))
+ results['Test_RadiusServer'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format(
+ RADIUS_USERNAME, RADIUS_PASSWORD, IP_RS, RADIUS_SECRET))
# Testiranje podatkovne base mysql
- results['mysql_login'] = sR.run('mysql -u {MYSQL_ADMIN_USER} -p {MYSQL_ADMIN_PASSWORD}'.format(**locals()))
- results['database_connect'] = sR.run('USE {MYSQL_DB_NAME}'.format(**locals()))
- results['select_from_users'] = sR.run('SELECT username, password FROM users;')
- sR.run('INSERT INTO users (username, password) VALUES ({MYSQL_TEST_USER}, {MYSQL_TEST_PASSWORD});')
- sR.run('\q');
+ mysql = pexpect.spawn('mysql -u {MYSQL_ADMIN_USER} -p{MYSQL_ADMIN_PASSWORD} -h {IP_RS}'.format(**locals()))
+ mysql.expect("mysql>")
+ results['mysql_login'] = mysql.before
+ mysql.sendline('USE {MYSQL_DB_NAME}'.format(**locals()))
+ mysql.expect("mysql>")
+ results['database_connect'] = mysql.before
+ mysql.sendline('SELECT username, password FROM users;')
+ mysql.expect("mysql>")
+ results['select_from_users'] = mysql.before
+ mysql.sendline("INSERT INTO radcheck (UserName, Attribute, Value, Op) VALUES ('{MYSQL_TEST_USER}', 'Cleartext-Password', '{MYSQL_TEST_PASSWORD}', ':=');".format(**locals()))
+ mysql.expect("mysql>")
+ results['radtest_OK'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format(
+ MYSQL_TEST_USER, MYSQL_TEST_PASSWORD, IP_RS, RADIUS_SECRET))
+ results['radtest_NOK'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format(
+ MYSQL_TEST_USER, "Flügzeug", IP_RS, RADIUS_SECRET))
+ results['radtest_NOK'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format(
+ MYSQL_TEST_USER, "Flügzeug", IP_RS, RADIUS_SECRET))
+ sT = pxssh.pxssh()
+ mysql.sendline("UPDATE radcheck SET UserName(value) VALUES('{RADIUS_NEW_PASSWORD}') where UserName='{RADIUS_USERNAME}' Attribute='Cleartext-Password';".format(**locals()))
+ sT.login(IP_RS, RADIUS_USERNAME, RADIUS_NEW_PASSWORD)
+ sT.prompt()
+ results['login_test'] = sT.before()
+ print results, mysql.before
+ mysql.sendline("UPDATE radcheck SET UserName(value) VALUES('{RADIUS_PASSWORD}') where UserName='{RADIUS_USERNAME}' Attribute='Cleartext-Password';".format(**locals()))
+ mysql.sendline("DELETE FROM radcheck where UserName='{MYSQL_TEST_USER}' and Attribute='Cleartext-Password';")
+ mysql.sendline('\q');
# Testiranje PAM s testnim uporabnikom
- sT.login(IP_RS, MYSQL_TEST_USER, MYSQL_TEST_PASSWORD)
-
return results
def gen_params(user_id, params_meta):
params = dict()
r = random.Random(user_id)
- for name, meta in params_meta.iteritems():
- params[name] = kpov_random_helpers.default_generators[meta.get('type', None)](r)
params['RADIUS_SECRET'] = kpov_random_helpers.alnum_gen(r, 8)
- params['RADIUS_PASSWORD'] = kpov_random_helpers.alnum_gen(r, 4)
- params['MYSQL_ADMIN_PASSWORD'] = kpov_random_helpers.alnum_gen(r, 4)
- net = kpov_random_helpers.IPv4_net_gen(r, 32)
- ip_radius_server = kpov_random_helpers.IPv4_addr_gen(r, net, 1)[0]
- params['IP_RS'] = ip_radius_server
+ params['RADIUS_PASSWORD'] = kpov_random_helpers.alnum_gen(r, 8)
+ params['RADIUS_USERNAME'] = kpov_random_helpers.username_gen(r)
+ params['MYSQL_ADMIN_USER'] = kpov_random_helpers.alnum_gen(r, 6)
+ params['MYSQL_ADMIN_PASSWORD'] = kpov_random_helpers.alnum_gen(r, 6)
+ params['MYSQL_DB_NAME'] = kpov_random_helpers.alnum_gen(r, 4)
+ params['MYSQL_SEED'] = str(r.random())
return params
def task_check(results, params):
|