summaryrefslogtreecommitdiff
path: root/tasks/mock_entrance_exam
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-02-24 21:05:27 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-02-24 21:05:27 +0100
commit8081a5520a441b43a8a7a73f3a90c7aacfaa8e10 (patch)
treec7f49bd33ed19d53afc0ee9df8b2c82c200c5910 /tasks/mock_entrance_exam
parent9963b74f777edf985540eac71b1ca095f88b8bca (diff)
Move everything one level up
Diffstat (limited to 'tasks/mock_entrance_exam')
-rw-r--r--tasks/mock_entrance_exam/howtos/en/index.html0
-rw-r--r--tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface1.jpgbin0 -> 211527 bytes
-rw-r--r--tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface2.jpgbin0 -> 213524 bytes
-rw-r--r--tasks/mock_entrance_exam/howtos/images/SimpleArbiter.jpgbin0 -> 217218 bytes
-rw-r--r--tasks/mock_entrance_exam/howtos/images/student-entrance-interface1.jpgbin0 -> 193759 bytes
-rw-r--r--tasks/mock_entrance_exam/howtos/images/student-entrance-interface2.jpgbin0 -> 195110 bytes
-rw-r--r--tasks/mock_entrance_exam/howtos/images/student-entrance.jpgbin0 -> 217218 bytes
-rw-r--r--tasks/mock_entrance_exam/howtos/si/index.html82
-rw-r--r--tasks/mock_entrance_exam/task.py313
9 files changed, 395 insertions, 0 deletions
diff --git a/tasks/mock_entrance_exam/howtos/en/index.html b/tasks/mock_entrance_exam/howtos/en/index.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/en/index.html
diff --git a/tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface1.jpg b/tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface1.jpg
new file mode 100644
index 0000000..8953de7
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface1.jpg
Binary files differ
diff --git a/tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface2.jpg b/tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface2.jpg
new file mode 100644
index 0000000..4eeb5e0
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/images/SimpleArbiter-interface2.jpg
Binary files differ
diff --git a/tasks/mock_entrance_exam/howtos/images/SimpleArbiter.jpg b/tasks/mock_entrance_exam/howtos/images/SimpleArbiter.jpg
new file mode 100644
index 0000000..4df497e
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/images/SimpleArbiter.jpg
Binary files differ
diff --git a/tasks/mock_entrance_exam/howtos/images/student-entrance-interface1.jpg b/tasks/mock_entrance_exam/howtos/images/student-entrance-interface1.jpg
new file mode 100644
index 0000000..3174913
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/images/student-entrance-interface1.jpg
Binary files differ
diff --git a/tasks/mock_entrance_exam/howtos/images/student-entrance-interface2.jpg b/tasks/mock_entrance_exam/howtos/images/student-entrance-interface2.jpg
new file mode 100644
index 0000000..5679dae
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/images/student-entrance-interface2.jpg
Binary files differ
diff --git a/tasks/mock_entrance_exam/howtos/images/student-entrance.jpg b/tasks/mock_entrance_exam/howtos/images/student-entrance.jpg
new file mode 100644
index 0000000..4df497e
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/images/student-entrance.jpg
Binary files differ
diff --git a/tasks/mock_entrance_exam/howtos/si/index.html b/tasks/mock_entrance_exam/howtos/si/index.html
new file mode 100644
index 0000000..f10bcf1
--- /dev/null
+++ b/tasks/mock_entrance_exam/howtos/si/index.html
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Preparation_mock_entrance_exam_HowTo</title>
+</head>
+<body><span style="font-family: Georgia, Times New Roman, Times, serif; ">
+ <strong><h1>MOCK ENTRANCE EXAM - HOWTO</h1></strong>
+
+<h2>1) POSTAVITEV VIRTUALK</h2>
+
+Najprej prenesi obe sliki za virtualki iz sistema kpov-judge, 2. naloga. Če se sliki ne naložita takoj, malo počakaj in osveži stran.
+Ustvari novo virtualko imenovano "Student", tip je načeloma "Linux" ter verzija "Ubuntu (64-bit)" - lahko pa je tudi karkoli drugega. Določi ustrezno količino pomnilnika, ki bo na voljo napravi, izberi možnost rabe obstoječe slike navidezne naprave ter izberi prenešeno datoteko "student-entrance.vdi". Klikni ustvari. <br> <img src="../images/student-entrance.jpg" alt="ni slike" width="600" height="400"></li> <br>
+Prejšnji postopek ponovi še za "SimpleArbiter", "Linux", "Ubuntu (64-bit)", "simplearbiter.vdi". <br> <img src="../images/SimpleArbiter.jpg" alt="ni slike" width="600" height="400"></li> <br>
+
+<h2>2) OMREŽNE NASTAVITVE VIRTUALK</h2>
+
+V navodilih naloge lahko vidimo, da morata biti obe virtualki povezani v internet ter povezani med seboj prek nekega notranjega omrežja.
+Na "SimpleArbiter" nastavimo pod Settings->Network->Adapter 1; Enable network adapter "check", Attached to: NAT. ->Adapter 2; Enable network adapter "check", Atached to: Internal Network. <br> <img src="../images/SimpleArbiter-interface1.jpg" alt="ni slike" width="600" height="400"></li> <img src="../images/SimpleArbiter-interface2.jpg" alt="ni slike" width="600" height="400"></li> <br>
+Na "Student" je postopek nastavitve enak kot na "SimpleArbiter". <br> <img src="../images/student-entrance-interface1.jpg" alt="ni slike" width="600" height="400"></li> <img src="../images/student-entrance-interface2.jpg" alt="ni slike" width="600" height="400"></li> <br>
+
+OPOMBA: Pozoren je treba biti, da sta oba vmesnika, ki sta povezana na notranje omrežje (Internal Nerwork) povezana preko istega omrežja, npr. "intnet".
+
+<h2>3) ZAGON VIRTUALK IN POSOTPEK NALOGE</h2>
+
+SA - SimpleArbiter
+STUD - Student
+
+Najprej zaženemo obe vritualki, to storimo s klikom na gumb start.
+Na SA se prijavimo z uporabniškim imenom "tester" ter geslom "tester"
+
+<h3>3.1) POSKRBIMO ZA MREŽO</h3>
+
+<h4>3.1.1) SPREMEMGA GESLA ZA ROOT</h4>
+
+Z uporabo ukaza /sbin/ifconfig preverimo, ali so vmesniki pravilno nastavljeni. Kaj kmalu ugotovimo, da je na SA aktiven samo en vmesnik. Za nastavljanje omesnikov moramo najprej postati "root", torej uporabnik, ki ima pooblastila za urejanje sistemskih nastavitev.
+Najprej ponovno zaženemo virtualko: "sudo reboot", potrdimo z geslom "tester".
+V GRUB meniju (zagonski meni) nato pritisnemo tipko "e", ki omogoča spreminjanje ukazov pred zagonom. Vrstico "53d ro" spremenimo v "53d rw init=/bin/bash". Pritisnemo "F10" in sprožimo zagon naprave.
+Sedaj lahko kot super uporabnik zamenjaš geslo za root, to storiš z ukazom "passwd", sistem te nato vpraša za novo geslo, po vnosu pa še za potrditev gesla. Geslo je uspešno spremenjeno, spremembe pa je potrebno še shraniti na disk, to storiš z ukazom "mount -o remount,ro /", izvedi še ukaz "sync", da se podatki res zapišejo na disk. Sedaj lahko virtualko ponovno zaženeš kar iz Machine->Reset.
+
+<h4>3.1.2) NASTAVIMO OMREŽNE VMESNIKE</h4>
+
+V virtualko SA se sedaj prijavimo kot uporabnik "root" ter s spremenjenim geslom "karsinastavil".
+Sedaj spremenimo nastavitve omrežnih vmesnikov tako, da bodo naslovi ustrezali tistim v navodilih. Izvedemo ukaz "ifconfig enp0s8 10.0.2.129 netmask 255.255.255.128 up"
+Preklopimo na virtualko STUD (uporabnik "root", geslo "kaboom") ter izvedemo podoben ukaz "ifconfig enp0s8 10.0.2.X netmassk 255.255.255.128", kjer je X podatek iz navodil naloge.
+Notranje omrežje testiramo tako, da pošljemo ping iz SA do STUD z ukazom "ping NASLOV", kjer je NASLOV omrežni naslov na STUD, ki je povezan na notranje omrežje (nastavitev iz prejšnjega koraka).
+SUPER, omrežje deluje, gremo naprej. Če ne deluje, preveri pravilnost naslovov na SA in STUD, bodi pozoren na dolžino maske ter na morebitne zatipke.
+
+<h3>3.2) "ZLONAMERNI" PROGRAM</h3>
+
+V navodilih naloge je podano ime programa, ki naj bi ob svojem zagonu pokvaril nastavitve omrežnih vmesnikov na STUD. Z ukazom "ps xa | grep IMEPROGRAMA" preverimo, če se program izvaja. V izpisu ugotovimo, da se najvrjetneje ne izvaja, zato lahko zadevo ignoriramo. Če bi se program izvajal, bi bilo potrebno ukrepati ter ga na nek način izbrisati oz. mu onemogočiti spreminjanje omrežnih vmesnikov (najlažje bi bilo uporabiti ukaz "kill", ki kot argument prejme PID (prvi stolpec prejšnjega izpisa) ter konča izvajanje tega procesa). Več o ukazu "kill" si preberi na spletu!
+
+<h3>3.3) PREVAJANJE PROGRAMA</h3>
+
+Najprej si odpremo novo konzolo na STUD "alt+F2" ter se prijavimo kot "student" z geslom "vaje".
+Z ukazom "ls" preverimo vsebino domačega direktorija uporabnika student. Izpisati bi se morala datoteka, ki jo imamo podano v navodilih. To datoteko moramo najprej odpreti z ukazom "vim IMEDATOTEKE". Datoteko moramo sedaj popraviti tako, da odstranimo odvečne črke, to storimo tako, da izvedemo ukaz ":%s/[QXW]*//g", sedaj izvedemo še ":syn on" in si obarvamo kodo. Izhod iz urejevalnika ":wq".
+Ta program sedaj z ukazom "gcc IMEPREVEDENEGAPROGRAMA IMEDATOTEKE" prevedemo v nov program, kjer je IMEPREVEDENEGAPROGRAMA izhodni program, katerega ime je prav tako podano v navodilih, IMEDATOTEKE pa ime pravkar popravljene datoteke.
+
+<h3>3.4) SKRIPTA</h3>
+
+Sedaj bomo napisali nov program/skripto, uporabimo urejevalnik nano; "nano IMESKRIPTE", kjer je IMESKRIPTE podano v navodilih naloge.
+V skripto zapišemo sledeče;<br>
+ <br>
+----BREZ TE VRSTICE-------<br>
+ <br>
+#!/bin/bash<br>
+<br>
+echo -n $SPREMENLJIVKA | /home/student/IMEPREVEDENEGAPROGRAMA "argument" 2> /home/student/IMEDATOTEKE_STDERR | grep "ma" > /home/student/IMEDATOTEKE_STDOUT<br>
+ <br>
+----BREZ TE VRSTICE-------<br>
+ <br>
+Datoteko shranimo "ctrl+x" ter potrdimo z "y" in enter.
+Datoteko sedaj spremenimo v program "chmod +x IMESKRIPTE"
+
+<h2>4) TESTIRANJE NALOGE</h2>
+
+Preklopimo nazaj na SA ter odpremo novo konzolo "alt+F2", vpišemo se kot uporabnik "tester" z geslom "tester" in poženemo program "./test_task.py"
+Izpolnimo vsa polja; URL "https://kpov.fri.uni-lj.si/kpov_judge/tasks", vpišemo svoje uporabniško ime in geslo (za dostop do KPOV-JUDGE preko učilnice) npr. "jn1234@student.uni-lj.si geslozaucilnico", ime naloge "02-preparation-mock_entrance_exam". Sedaj se pojavijo še vaši vhodni in izhodni podatki za nalogo, preverite, če so pravilni; datoteka z izhodom, IP naslov SA, ime spremenljivke, ime "zlonamernega" programa, datoteka z napakami ter neko naljučno seme itd.
+Če program vrne 10 OK je naloga uspešno opravljena, sicer pa vrne število doseženih točk ter napako.
+ </span>
+</body>
+</html>
diff --git a/tasks/mock_entrance_exam/task.py b/tasks/mock_entrance_exam/task.py
new file mode 100644
index 0000000..ad51c2a
--- /dev/null
+++ b/tasks/mock_entrance_exam/task.py
@@ -0,0 +1,313 @@
+# TODO:
+# - check if everything is filled in (computers, params, preparation)
+# - improve scoring
+# - test
+# - switch to a real SSH/SFTP client to properly handle filenames
+
+instructions = {
+ 'si': '''\
+<p>
+Postavite dva navidezna računalnika - <em>SimpleArbiter</em> in <em>Student</em>. Oba naj bosta povezana na internet. Poleg tega mora biti <em>Student</em> na naslovu {{student_IP}} dostopen s <em>SimpleArbiter</em>.
+
+<p>
+Računajte, da se na <em>Student</em> ob zagonu zažene program {{net_prog_name}}, ki vam spreminja nastavitve mrežne kartice.
+
+<p>
+V domačem imeniku uporabnika <code>student</code> obstaja program <code>{{P_c}}</code> v programskem jeziku C.
+Prevedite ga v program z imenom <code>{{P_executable}}</code>. Izvorna koda je namenoma pokvarjena tako, da so vanjo vrinjeni nepotrebni znaki. Pred prevajanjem jo morate popraviti.
+
+<p>
+Napišite skripto ali program <code>{{P_script}}</code> v domačem imeniku uporabnika <code>student</code>, ki:
+
+<ul>
+<li>požene <code>{{P_executable}}</code> z argumentom <code>"{{arg_c}}"</code> in mu na standardni vhod pripelje vrednost spremenljivke <code>{{env_c}}</code>;
+<li>vse, kar <code>{{P_executable}}</code> izpiše na stderr, spravi v datoteko <code>{{out_stderr_c}}</code>; in
+<li>vse vrstice, ki jih <code>{{P_executable}}</code> izpiše na stdout in vsebujejo zaporedje znakov <code>ma</code>, zapiše v <code>{{out_stdout_c}}</code>.
+</ul>
+
+<p>
+Lastnik vseh ustvarjenih datotek mora biti uporabnik <code>student</code>. Gesla uporabnika <code>student</code> (<code>vaje</code>) ne smete spreminjati.
+''',
+ 'en': '''\
+<p>
+Set up two virtual machines - <em>SimpleArbiter</em> and <em>Student</em>. Both should be connected to the internet. <em>Student</em> should also be accessible from <em>SimpleArbiter</em> at the address <code>{{student_IP}}</code>.
+
+<p>
+Keep in mind that a program called <code>{{net_prog_name}}</code> starts on <em>Student</em> on each boot. This program may change your network settings.
+
+<p>
+There is a program called <code>{{P_c}}</code> in <code>student</code>’s home directory. Compile it into a program called <code>{{P_executable}}</code>. The source code is intentionally broken so that unneccessarry characters are inserted into the file. You have to fix the file before compiling.
+
+<p>
+Also, write a script or program called <code>{{P_script}}</code> in <code>student</code>’s home directory. The script should:
+
+<ul>
+<li>run <code>{{P_executable}}</code> with the argument <code>{{arg_c}}</code> and pipe the value of the environment variable <code>{{env_c}}</code> into <code>{{P_executable}}</code>’s standard input;
+<li>redirect stderr of <code>{{P_executable}}</code> into a file called <code>{{out_stderr_c}}</code>; and
+<li>save each line which <code>{{P_executable}}</code> outputs and which contains the character sequence <code>ma</code> into <code>{{out_stdout_c}}</code>.
+</ul>
+
+<p>
+The owner of all created files should be <code>student</code>. You are not allowed to change <code>student</code>’s password (<code>vaje</code>).
+''',
+}
+
+computers = {
+ 'SimpleArbiter': {
+ 'disks': [
+ {
+ 'name': 'simpleArbiter',
+ },
+ ],
+ 'network_interfaces': [
+ {'network': 'net1'},
+ {'network': 'net2'},
+ ],
+ 'flavor': 'm1.tiny',
+ 'config_drive': True,
+ },
+ 'Student': {
+ 'disks': [
+ {'name': 'student-entrance'}
+ ],
+ 'flavor': 'm1.tiny',
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'net3'}],
+ 'config_drive': True,
+ }
+}
+
+networks = {
+ 'net1': {
+ 'public': False,
+ },
+ 'net2': {
+ 'public': True,
+ },
+ 'net3': {
+ 'public': True,
+ }
+}
+
+params_meta = {
+ 'student_IP': {
+ 'descriptions': { 'si': 'IP naslov SimpleStudent', 'en': 'IP address of SimpleStudent',
+ }, 'w': False, 'public': True, 'type': 'IP', 'generated': True,
+ },
+ 'net_prog_name': {
+ 'descriptions': { 'si': 'Ime programa, ki ponastalvlja naslov', 'en': 'The name of the program resetting the network'
+ }, 'w': False, 'public': True, 'type': 'filename', 'generated': True,
+ },
+ 'P_c': {
+ 'descriptions': { 'si': 'Datoteka s programom v C', 'en': 'Filename of the program in C',
+ }, 'w': False, 'public': True, 'type': 'filename', 'generated': True,
+ },
+ 'P_executable': { 'descriptions': { 'si': 'Ime prevedenega programa v C', 'en': 'Filename of the compiled C program'
+ }, 'w': False, 'public': True, 'type': 'filename', 'generated': True,
+ },
+ 'arg_c': {
+ 'descriptions': { 'si': 'Vrednost argumenta', 'en': 'Argument value',
+ }, 'w': False, 'public': True, 'type': 'short_text', 'generated': True,
+ },
+ 'env_c': {
+ 'descriptions': { 'si': 'Ime okoljske spremenljivke', 'en': 'The name of the environment environment',
+ }, 'w': False, 'public': True, 'type': 'short_text', 'generated': True,
+ },
+ 'out_stderr_c': {
+ 'descriptions': { 'si': 'Datoteka z napakami', 'en': 'File to store errors',
+ }, 'w': False, 'public': True, 'type': 'filename', 'generated': True,
+ },
+ 'P_script': {
+ 'descriptions': { 'si': 'Ime skripte', 'en': 'Filename of the script',
+ }, 'w': False, 'public': True, 'type': 'filename', 'generated': True,
+ },
+ 'out_stdout_c': {
+ 'descriptions': { 'si': 'Datoteka z izhodom', 'en': 'File to store the output',
+ }, 'w': False, 'public': True, 'type': 'filename', 'generated': True,
+ },
+ 'param_gen_seed': {
+ 'descriptions': { 'si': 'Nakljucno seme', 'en': 'Random seed',
+ }, 'w': False, 'public': True, 'type': None, 'generated': True,
+ },
+ 'c_destroy_gen_seed': {
+ 'descriptions': { 'si': 'Nakljucno seme za kvarjenje kode v C', 'en': 'Random seed for destroying the C code',
+ }, 'w': False, 'public': False, 'type': None, 'generated': True,
+ }
+
+}
+
+def task(student_IP, net_prog_name,
+ P_c, P_executable, arg_c, env_c, out_stderr_c, out_stdout_c, P_script,
+ param_gen_seed):
+ import random
+
+ r = random.Random(int(param_gen_seed))
+ env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
+ arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
+ stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
+
+ return kpov_util.ssh_test(student_IP, 'student', 'vaje', (
+ ('script_ls', 'ls -l {}'.format(P_script)),
+ ('executable_ls', 'ls -l {}'.format(P_executable)),
+ ('script_run', 'export {}={}; {}'.format(env_c, env_val, P_script)),
+ ('script_stderr', 'cat {}'.format(out_stderr_c)),
+ ('script_stdout', 'cat {}'.format(out_stdout_c)),
+ ('prog_stdout', 'echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val)),
+ ('prog_stderr', 'echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val)),
+ ))
+
+def gen_params(user_id, params_meta):
+ import random
+ r = random.Random(user_id+'evil cornholio')
+ params = kpov_util.default_gen(user_id, params_meta)
+ homedir = '/home/student/'
+ params['env_c'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in range(5)])
+ params['P_c'] = "".join([r.choice('abcdefghijklmnoprst') for i in range(5)]) + ".c"
+ params['param_gen_seed'] = str(r.randint(0, 2**24))
+ params['c_destroy_gen_seed'] = str(r.randint(0, 2**24))
+ dest_net = kpov_util.IPv4_subnet_gen(r, '10.0.2.128/26', 26)
+ params['student_IP'] = kpov_util.IPv4_addr_gen(r, dest_net)[0]
+ for k in ['P_c', 'P_executable', 'out_stderr_c', 'P_script', 'out_stdout_c']:
+ params[k] = homedir + params[k]
+ return params
+
+def task_check(results, params):
+ import os
+ def test_out_gen(arg, var):
+ s_out = ""
+ s_err = ""
+ r = 0
+ arg_len = len(arg)
+ env_len = len(var)
+ for i in range(100):
+ s_out += chr(32 + ((ord(arg[i % arg_len]) ^ ord(var[i % env_len])) % 64))
+ r += ord(arg[i % arg_len]) + ord(var[i % env_len]) + i;
+ if (i % 17 == 0):
+ s_out += "RAUS\r\n";
+ if (i % 29 == 0):
+ s_out += 'ma'
+ s_err += chr((r % 31) + ord('A'));
+ if (i % 23 == 0):
+ s_err += "PATACIS\r\n"
+ retval = r % 16
+ s_err += '\r\n'
+ s_out += '\r\n'
+ return(s_out, s_err, retval)
+ score = 0
+ hints = []
+ if results['ssh'] is not True:
+ hints += ['ssh failed: ' + results['ssh']]
+ r = random.Random(int(params['param_gen_seed']))
+ env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
+ arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
+ stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
+ expected_script_stdout, expected_script_stderr, rval = test_out_gen(
+ params['arg_c'], env_val
+ )
+ expected_script_stderr = 'cat {}\r\n'.format(params['out_stderr_c']) + expected_script_stderr
+ # hints += [expected_script_stderr, results['script_run'], results['script_stderr'], params['arg_c'], env_val]
+ if expected_script_stderr != results['script_stderr']:
+ hints += ['wrong script stderr']
+ else:
+ score += 2
+ split_stdout = expected_script_stdout.split('\r\n')
+ expected_script_stdout = "\r\n".join([ i for i in split_stdout if i.find('ma') >= 0])
+ expected_script_stdout = 'cat {}\r\n'.format(params['out_stdout_c']) + expected_script_stdout + "\r\n"
+ if expected_script_stdout != results['script_stdout']:
+ hints += ['wrong script stdout']
+ else:
+ score += 2
+ expected_prog_stdout, expected_prog_stderr, rval = test_out_gen(
+ arg_val, stdin_val
+ )
+ if expected_prog_stderr != results['prog_stderr'][-len(expected_prog_stderr):]:
+ hints += ['wrong program stderr']
+ else:
+ score += 2
+ if expected_prog_stdout != results['prog_stdout'][-len(expected_prog_stdout):]:
+ hints += ['wrong program stdout']
+ else:
+ score += 2
+ if results['script_ls'].find('-r') < 0:
+ hints += ['script not found']
+ else:
+ score += 1
+ if results['executable_ls'].find('xr') < 0:
+ hints += ['C executable not found']
+ else:
+ score += 1
+ return score, hints
+
+def prepare_disks(templates, task_params, global_params):
+ c_source = '''#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+/* Odstranite vse odvecne velike crke Q, W ali X in program se bo prevedel. */
+
+int main(int argc, char **argv){
+ unsigned char *arg;
+ unsigned char var[255];
+ int i, arg_len, env_len, r;
+ scanf("%s", var);
+ arg = argv[1];
+ arg_len = strlen(argv[1]);
+ env_len = strlen(var);
+ r = 0;
+ for (i = 0; i<100; i++){
+ printf("%c", 32 + (arg[i % arg_len] ^ var[i % env_len]) % 64);
+ r += (int)arg[i % arg_len] + (int)var[i % env_len] + i;
+ if (i % 17 == 0){
+ printf("RAUS\\n");
+ }
+ if (i % 29 == 0){
+ printf("ma");
+ }
+ fprintf(stderr, "%c", (r % 31) + 'A');
+ if (i % 23 == 0){
+ fprintf(stderr, "PATACIS\\n");
+ }
+ }
+ printf("\\n");
+ fprintf(stderr, "\\n");
+ return r % 16;
+}
+'''
+ evil_shell_source = """#!/bin/bash -e
+
+while true; do
+ /sbin/ifconfig eth1 10.0.4.19 2> /dev/null;
+ /sbin/ifconfig eth0 10.0.4.20 2> /dev/null;
+ /sbin/ifconfig eth2 10.0.4.21 2> /dev/null;
+ /sbin/ifconfig en0p3 10.0.4.19 2> /dev/null;
+ /sbin/ifconfig en0p8 10.0.4.20 2> /dev/null;
+ /sbin/ifconfig enp0s3 10.0.4.21 2> /dev/null;
+ /sbin/ifconfig enp0s8 10.0.4.21 2> /dev/null;
+ sleep 10;
+done;
+"""
+ import random
+ d = templates['student-entrance']
+ r = random.Random(task_params['c_destroy_gen_seed'])
+ destroyed_c_source = c_source[:110]
+ for c in c_source[110:]:
+ i = r.randint(0, 5)
+ if i == 1:
+ destroyed_c_source += 'QW'
+ if i == 2:
+ destroyed_c_source += 'XW'
+ if i == 3:
+ destroyed_c_source += 'QX'
+ destroyed_c_source += c
+ d.write(task_params['P_c'], destroyed_c_source)
+ d.chown(1000, 1000, task_params['P_c'])
+ sh_path = r.choice(['/usr/share/doc', '/var/lib', '/usr/local/share', '/etc/alternatives'])
+ sh_file = sh_path + '/' + task_params['net_prog_name']
+ d.write(sh_file, evil_shell_source)
+ d.chmod(0o775, sh_file)
+ d.write("/etc/rc.local", """#!/bin/sh -e
+export PATH=$PATH:{}
+nohup {} &
+
+exit 0
+""".format(sh_path, task_params['net_prog_name']))
+
+ write_default_config(templates['simpleArbiter'], global_params)