From 17f241009b1d6764b047152bf66a1764ef508009 Mon Sep 17 00:00:00 2001 From: thomashaw Date: Thu, 2 Nov 2023 13:04:26 +0000 Subject: [PATCH 1/2] AES Lab and RSA updates (3) --- .../templates/aes_file_enc_python3.md.erb | 12 +++++++++++- .../templates/symmetric_enc_aes_lab.xml.erb | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/aes_file_enc_python3.md.erb b/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/aes_file_enc_python3.md.erb index e3ce9f6a2..622420045 100644 --- a/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/aes_file_enc_python3.md.erb +++ b/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/aes_file_enc_python3.md.erb @@ -17,7 +17,9 @@ Open and read from the /etc/hosts file ```python3 >>> with open("/etc/hosts", "rb") as f: ->>> file = f.read() +... file = f.read() +... +>>> ``` You can generate random key using this command in a bash shell: @@ -39,6 +41,14 @@ You can inspect the contents of the ciphertext `>>> print(c)` +To write data to a file, open the file in *w*rite *b*inary mode +```python3 +>>> with open("/etc/hosts.enc", "wb") as f: +... f.write(c) +... +>>> +``` + To decrypt... diff --git a/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb b/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb index f4666c6d2..7e3ae97d9 100644 --- a/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb +++ b/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb @@ -247,7 +247,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= - Using Python3 and Cryptodome with AES in ECB mode and the key b"<%= $enc_file_python_key %>" encrypt the file: <%= $file_to_encrypt_path %> and store the ciphertext at: <%= $enc_file_stu_ct_path %> + Using Python3 and Cryptodome with AES in ECB mode and the key b"<%= $enc_file_python_key %>" encrypt the file: <%= $file_to_encrypt_path %> and write the ciphertext binary data to the file: <%= $enc_file_stu_ct_path %> python3 -c 'from Cryptodome.Cipher import AES; from Cryptodome.Util.Padding import pad,unpad; student_ct_file = open("<%= $enc_file_stu_ct_path %>","rb"); student_ct = student_ct_file.read(); k = b"<%= $enc_file_python_key %>"; e = AES.new(k, AES.MODE_ECB); target_plaintext_file = open("<%= $file_to_encrypt_path %>", "rb"); target_plaintext = target_plaintext_file.read(); ct = e.encrypt(pad(target_plaintext,16)); print(ct == student_ct)' @@ -256,7 +256,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= False - Something was not quite right... + Something was not quite right... Something was not quite right... From c4a2ff7c0fe5440a852df2718c1f072d429101e1 Mon Sep 17 00:00:00 2001 From: thomashaw Date: Thu, 2 Nov 2023 13:09:57 +0000 Subject: [PATCH 2/2] AES Lab and RSA updates (4) --- .../templates/asymmetric_enc_rsa_lab.xml.erb | 24 +++++++++---------- .../templates/symmetric_enc_aes_lab.xml.erb | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/generators/structured_content/hackerbot_config/asymmetric_enc_rsa/templates/asymmetric_enc_rsa_lab.xml.erb b/modules/generators/structured_content/hackerbot_config/asymmetric_enc_rsa/templates/asymmetric_enc_rsa_lab.xml.erb index ef9b31f2b..69fe4b53c 100644 --- a/modules/generators/structured_content/hackerbot_config/asymmetric_enc_rsa/templates/asymmetric_enc_rsa_lab.xml.erb +++ b/modules/generators/structured_content/hackerbot_config/asymmetric_enc_rsa/templates/asymmetric_enc_rsa_lab.xml.erb @@ -149,11 +149,11 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= 10 - Something was not quite right with your private key file + Something was not quite right with your private key file 01 - Something was not quite right with your public key file + Something was not quite right with your public key file 00 @@ -211,7 +211,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -242,7 +242,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -271,7 +271,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -298,7 +298,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -326,7 +326,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -353,7 +353,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -381,7 +381,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -408,7 +408,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -437,7 +437,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -464,7 +464,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. diff --git a/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb b/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb index 7e3ae97d9..b6bcf7bfb 100644 --- a/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb +++ b/modules/generators/structured_content/hackerbot_config/symmetric_enc_aes/templates/symmetric_enc_aes_lab.xml.erb @@ -200,7 +200,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -229,7 +229,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= ok - ok... your turn. + ok... your turn. @@ -278,7 +278,7 @@ Randomised instance generated by [SecGen](http://github.com/cliffe/SecGen) (<%= - +