summaryrefslogtreecommitdiff
path: root/kpov_judge
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge')
-rw-r--r--kpov_judge/tasks/edit_find_grep_compile_convert/task.py109
1 files changed, 81 insertions, 28 deletions
diff --git a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
index 1d7f210..60353fd 100644
--- a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
+++ b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
@@ -19,12 +19,12 @@ Na SmallStudent se lahko prijaviš kot root z geslom kaboom.
Poskrbi, da bo SmallStudent s SimpleArbiter dostopen na naslovu {testip}.
-Na SmallStudent ustvari uporabnika {testuser} z geslom {pass}.
+Na SmallStudent ustvari uporabnika {testuser} z geslom {passwd}.
Na SmallStudent je nekje v domačem imeniku uporabnika "bilbo" skrita datoteka, ki vsebuje niz {magicstr}.
Skopiraj jo v domači imenik {testuser} in poimenuj {dstfile}.
Poskrbi, da bo lastnik {testuser}, skupina pa naj ostane nespremenjena.
-Brati naj jo ima pravico samo lastnik.
+Brati naj jo ima pravico samo lastnik, pisati lastnik in skupina, poganjati nihče.
V {dstfile} zamenjaj vse vrstice oblike poXYZlz, kjer so XYZ poljubni znaki, tako, da bo namesto XYZ niz "kaka".
Napiši program v poljubnem programskem jeziku, ki kot argument sprejme število B med 0 in 7.
@@ -42,13 +42,13 @@ You can log in as root on SimpleStudent with the password kaboom.
Make sure that SmallStudent is accessible from SimpleArbiter on IP {testip}.
-Create a user {testuser} with the password {pass} on SmallStudent.
+Create a user {testuser} with the password {passwd} on SmallStudent.
There is a file containing {magicstr} hidden somewhere in the home directory of
user "bilbo".
Copy the into the home directory of user bilbo and name it {dstfile}.
Change the owner to {testuser} and leave the group unchanged.
-Make sure only the owner has the right to read it.
+Make sure only the owner has the right to read it, only the owner and group members have the right to write to it and noone has the right to execute it.
In {dstfile}, replace all lines of the form poXYZlz where XYZ are arbitrary characters so that XYZ is replaced by "kaka".
Write a program in any programming language.
@@ -123,7 +123,7 @@ params_meta = {
'type': 'username',
'generated': True,
},
- 'pass': {
+ 'passwd': {
'descriptions': {
'si': 'Geslo na SmallStudent',
'en': 'Password on SmallStudent',
@@ -181,21 +181,30 @@ params_meta = {
'en': 'random seed for hiding the file',
},
'w': False,
- 'public': True,
+ 'public': False,
'type': None,
'generated': True,
},
}
-def task(host, folder):
+def task(testip, testuser, passwd, magicstr, dstfile, progname, pubseed):
from pexpect import pxssh
+ import random
# ideally, this would be done using a SFTP client instead of pxssh
target = pxssh.pxssh()
- target.login(host, 'test', 'test')
+ target.login(testip, testuser, passwd)
results = {
- 'files': target.run('ls -1').split('\n'), # XXX: file may have newlines
- 'contents': target.run("cat *"), # XXX: may include other files in $HOME
+ 'dst_ls': target.run('ls -l ~/{}'.format(dstfile))
+ 'dst_file_contents': target.run('cat ~/{}'.format(dstfile))
+ 'home_ls': target.run('ls ~/')
}
+ tita_return = ""
+ r = random.Random(pubseed)
+ for i in range(10):
+ b = r.randint(0, 7)
+ x = oct(r.randint(37, 127)).replace('o', '')
+ tita_return += target.run('echo -e "\0{}" | ~/{} {}'.format(x, progname, b))
+ results['tita_return'] = tita_return
target.logout()
return results
@@ -206,8 +215,8 @@ def gen_params(user_id, params_meta):
params['testip'] = kpov_random_helpers.IPv4_addr_gen(r,
network = '10.94.80.0/19', n_generated=1)[0]
params['testuser'] = kpov_random_helpers.default_generators['username'](r)
- params['pass'] = kpov_random_helpers.alnum_gen(8)
- params['magicstr'] = kpov_random_helpers.alnum_gen(8)
+ params['passwd'] = kpov_random_helpers.alnum_gen(r, 8)
+ params['magicstr'] = "".join([r.choice("qwerztlpoQWERTPOL") for i in range(10)])
params['dstfile'] = kpov_random_helpers.default_generators['filename'](r)
params['progname'] = kpov_random_helpers.default_generators['filename'](r)
while params['dstfile'] == params['progname']:
@@ -219,10 +228,42 @@ def gen_params(user_id, params_meta):
def task_check(results, params):
import os
- if rl == tl:
- score += 4
+ import re
+ hints = []
+ score = 0
+ hidden_contents = params['magicstr']
+ r = random.Random(params['rndseed'])
+ for i in range(1000):
+ x = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)])
+ x += "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)])
+ x += r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"])
+ hidden_contents += x + "\n\r"
+ expected_contents = re.sub("\n\rpo.*lz\n",
+ "\n\rpokakalz\n",
+ hidden_contents,
+ re.MULTILINE)
+ expected_contents = re.sub("\n\rpo.*lz$",
+ "\n\rpokakalz",
+ expected_contents,
+ re.MULTILINE)
+ if results["dst_file_contents"] == expected_contents:
+ score += 3
+ else:
+ hints += ["wrong file contents"]
+ expected_ls = "-rw--w---- 1 {testuser} bilbo .* {dstfile}".format(**params)
+ if re.match(expected_ls, results["dstfile_ls"]):
+ score += 3
+ else:
+ hints += ["missing file or wrong user/permissions"]
+ if results["home_ls"].find(params['progname']) > -1:
+ score += 2
+ else:
+ hints += ["missing program"]
+ expected_tita = ""
+ if results["tita_return"] == expected_tita:
+ score += 2
else:
- hints += ["wrong files"]
+ hints += ["program output incorrect" + results["tita_return"]]
return score, hints
@@ -233,25 +274,37 @@ def prepare_disks(templates, task_params, global_params):
#print params
#print templates
d = templates['SmallStudent']
+ # first create the file contents to make it easyer to check.
+ hidden_contents = task_params['magicstr']
r = random.Random(task_params['rndseed'])
+ for i in range(1000):
+ x = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)])
+ x += "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)])
+ x += r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"])
+ hidden_contents += x + "\n"
# create hidden file
dir_list = ['Qlipper', 'Thunar', 'blender', 'autostart', 'kazam', 'mc', 'netsurf', 'pulse', 'qupzilla', 'radare2', 'teamviewer', 'texstudio', 'vlc']
- rndstr1 = r.choice(dir_list)
ending_list = ['rc', '.conf', '']
start_list = ['net', 'dev', 'doc', 'lib', 'time', 'conf']
- rndstr2 = r.choice(start_list) + \
- r.choice("abcdexghijuop") + r.choice(ending_list)
- hidden_file_dir = os.path.join('/home/bilbo/.config',
- rndstr1)
- d.mkdir(hidden_file_dir)
- hidden_file_name = os.path.join(hidden_file_dir,
+ r.shuffle(dir_list)
+ file_letters = ["mod", "co"]
+ for potential_dir in dir_list:
+ try:
+ potential_dir = os.path.join('/home/bilbo/.config', potential_dir)
+ d.mkdir(potential_dir)
+ d.chown(1002, 1002, potential_dir)
+ except:
+ pass
+ for i in r.randint(2, 20):
+ rndstr2 = r.choice(start_list) + \
+ r.choice(file_letters) + r.choice(ending_list)
+ hidden_file_name = os.path.join(potential_dir,
rndstr2)
- d.chown(1002, 1002, hidden_file_dir)
- d.chown(1002, 1002, hidden_file_name)
- # TODO create the file contents
- s = task_params['magicstr']
- # add poXYZlz lines to s
- d.write(hidden_file_name, s)
+ d.chown(1002, 1002, hidden_file_name)
+ d.write(hidden_file_name, hidden_contents)
+ file_letters = ["stamp", "", "dev", "re"]
+ hidden_contents = "".join([r.choice("asdfghjkyxcvbnm1234567890 \n") for j in range(10000)])
+ file_letters = file_letters + ["mod", "co"]
# TODO create some additional files
write_default_config(templates['simpleArbiterDhcpGW'], global_params)