diff options
-rw-r--r-- | users/wpcarro/scratch/picoctf/.skip-subtree | 0 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/README.md | 3 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_144.py | 11 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_156.py | 13 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_166/ende.py | 60 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_166/flag.txt.en | 1 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_166/pw.txt | 1 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_166/shell.nix | 7 | ||||
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_170/README.md | 11 |
9 files changed, 107 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/picoctf/.skip-subtree b/users/wpcarro/scratch/picoctf/.skip-subtree new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/.skip-subtree diff --git a/users/wpcarro/scratch/picoctf/README.md b/users/wpcarro/scratch/picoctf/README.md new file mode 100644 index 000000000000..03a49817f745 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/README.md @@ -0,0 +1,3 @@ +# picoCTF + +My solutions for some of the questsions at https://play.picoctf.org/practice. diff --git a/users/wpcarro/scratch/picoctf/challenge_144.py b/users/wpcarro/scratch/picoctf/challenge_144.py new file mode 100644 index 000000000000..570a7fd5a77b --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_144.py @@ -0,0 +1,11 @@ +def rotate_alpha(x, n): + def rotate_char(c, n): + offset = 'A' if c.isupper() else 'a' + return chr((ord(c) - ord(offset) + n) % 26 + ord(offset)) + return "".join([rotate_char(c, n) if c.isalpha() else c for c in x]) + +xs = [ + "cvpbPGS{arkg_gvzr_V'yy_gel_2_ebhaqf_bs_ebg13_Ncualgvd}", +] +for x in xs: + print(rotate_alpha(x, 13)) diff --git a/users/wpcarro/scratch/picoctf/challenge_156.py b/users/wpcarro/scratch/picoctf/challenge_156.py new file mode 100644 index 000000000000..8c87a1ce7694 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_156.py @@ -0,0 +1,13 @@ +bytestring = [ + 112, 105, 99, 111, 67, 84, 70, 123, 103, 48, 48, 100, 95, 107, 49, 116, + 116, 121, 33, 95, 110, 49, 99, 51, 95, 107, 49, 116, 116, 121, 33, 95, 57, + 98, 51, 98, 55, 51, 57, 50, 125, 10, +] + +def decode(xs): + result = [] + for x in xs: + result.append(chr(x)) + return "".join(result) + +print(decode(bytestring)) diff --git a/users/wpcarro/scratch/picoctf/challenge_166/ende.py b/users/wpcarro/scratch/picoctf/challenge_166/ende.py new file mode 100644 index 000000000000..08395f920909 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_166/ende.py @@ -0,0 +1,60 @@ + +import sys +import base64 +from cryptography.fernet import Fernet + + + +usage_msg = "Usage: "+ sys.argv[0] +" (-e/-d) [file]" +help_msg = usage_msg + "\n" +\ + "Examples:\n" +\ + " To decrypt a file named 'pole.txt', do: " +\ + "'$ python "+ sys.argv[0] +" -d pole.txt'\n" + + + +if len(sys.argv) < 2 or len(sys.argv) > 4: + print(usage_msg) + sys.exit(1) + + + +if sys.argv[1] == "-e": + if len(sys.argv) < 4: + sim_sala_bim = input("Please enter the password:") + else: + sim_sala_bim = sys.argv[3] + + ssb_b64 = base64.b64encode(sim_sala_bim.encode()) + c = Fernet(ssb_b64) + + with open(sys.argv[2], "rb") as f: + data = f.read() + data_c = c.encrypt(data) + sys.stdout.write(data_c.decode()) + + +elif sys.argv[1] == "-d": + if len(sys.argv) < 4: + sim_sala_bim = input("Please enter the password:") + else: + sim_sala_bim = sys.argv[3] + + ssb_b64 = base64.b64encode(sim_sala_bim.encode()) + c = Fernet(ssb_b64) + + with open(sys.argv[2], "r") as f: + data = f.read() + data_c = c.decrypt(data.encode()) + sys.stdout.buffer.write(data_c) + + +elif sys.argv[1] == "-h" or sys.argv[1] == "--help": + print(help_msg) + sys.exit(1) + + +else: + print("Unrecognized first argument: "+ sys.argv[1]) + print("Please use '-e', '-d', or '-h'.") + diff --git a/users/wpcarro/scratch/picoctf/challenge_166/flag.txt.en b/users/wpcarro/scratch/picoctf/challenge_166/flag.txt.en new file mode 100644 index 000000000000..1c4d245811e8 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_166/flag.txt.en @@ -0,0 +1 @@ +gAAAAABgUAIWsYfVayn4m1dKle5X91HrZW_MIRAW4ILPgf4gD6jalLF4PysYB5_YTpDwclcQPqw_0xTxanpJ_Urx5Vi6mTeBA_rWPA_WQLvVXXHp1mG3EpOgY8Na1_NIAfc9LceH_L2o \ No newline at end of file diff --git a/users/wpcarro/scratch/picoctf/challenge_166/pw.txt b/users/wpcarro/scratch/picoctf/challenge_166/pw.txt new file mode 100644 index 000000000000..a4c1c7ae6631 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_166/pw.txt @@ -0,0 +1 @@ +67c6cc9667c6cc9667c6cc9667c6cc96 diff --git a/users/wpcarro/scratch/picoctf/challenge_166/shell.nix b/users/wpcarro/scratch/picoctf/challenge_166/shell.nix new file mode 100644 index 000000000000..07a3a2e281b4 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_166/shell.nix @@ -0,0 +1,7 @@ +{ pkgs, ... }: + +let + python =pkgs.python3.withPackages (pypkgs: with pypkgs; [ + cryptography + ]); +in python.env diff --git a/users/wpcarro/scratch/picoctf/challenge_170/README.md b/users/wpcarro/scratch/picoctf/challenge_170/README.md new file mode 100644 index 000000000000..2507208f5c1a --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_170/README.md @@ -0,0 +1,11 @@ +# challenge 170 + +The following should work on most Linux distros, but it didn't for me on NixOS: + +```shell +chmod u+x ./warm +./warm -h +``` + +So instead, just call `strings` on the exectuable to search for the help text, +which contains the flag. |