Hack The Box-Challenges-Misc-M0rsarchive

解压压缩包,里面是一张图片和一个新的zip文件

在这里插入图片描述

图片放大后的图案是----.

在这里插入图片描述

考虑到为莫斯密码,将其解密

在这里插入图片描述

密码为9,继续解压缩包

在这里插入图片描述

又是一张莫斯密码图加压缩包,写一段脚本去解密图片中的莫斯密码,并自动解压缩包

import re
import os
import sys
import zipfile
from PIL import Image


def get_pass(morse_list):
    password = ""
    MORSE_CODE_DICT = {
   '.-': 'a', '-...': 'b', '-.-.': 'c', '-..': 'd','.': 'e', '..-.': 'f', '--.': 'g', '....': 'h','..': 'i', '.---': 'j', '-.-': 'k', '.-..': 'l','--': 'm', '-.': 'n', '---': 'o', '.--.': 'p','--.-': 'q', '.-.': 'r', '...': 's', '-': 't','..-': 'u', '...-': 'v', '.--': 'w', '-..-': 'x','-.--': 'y', '--..': 'z', '-----': '0', '.----': '1','..---': '2', '...--': '3', '....-': '4', '.....': '5','-....': '6', '--...': '7', '---..': '8', '----.': '9','-..-.': '/', '.-.-.-': '.', '-.--.-': ')', '..--..': '?','-.--.': '(', '-....-': '-', '--..--': ','}
    for morse in morse_list:
        password += MORSE_CODE_DICT.get(morse)
    return password


def get_morse():
    fp = open('./pwd.png', 'rb')
    image = Image.open(fp)
    pixel = list(image.getdata())
    background = pixel[0]
    chars = []
    for i,v in enumerate(pixel):
        if v == background:
                chars.append(" ")
        else:
                chars.append("*")
    output =  "".join(chars)
    """正则匹配测试建议:https://regex101.com/
    ^  : asserts position at start of a line
    $  : asserts position at the end of a line
    \s : matches any whitespace character (equivalent to [\r\n\t\f\v ])
    *  : matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    \* : matches the character *
    {3}: matches the previous token exactly 3 times
    """
    output = re.sub(r'^\s*', '', output)   #匹配开头的任意个空白字符,并替换为空
    output = re.sub(r'\s*$', '', output)   #匹配结尾的任意个空白字符,并替换为空
    output = re.sub(r'\*{3}', '-', output) #匹配3个*号,并替换为字符"-"
    output = re.sub(r'\*', '.', output)    #匹配单个*号,并替换为字符"."
    output = re.sub(r'\s{2,}', ' | ', output)  #(用于处理多行摩斯密码的情况)匹配两个以上空白字符,如果存在,就替换为"|"
    output = re.sub(r'\s', '', output)     #匹配空白字符,并替换为空
    output = output.split('|')
    fp.close()
    return output


def unzip_file(path, number, password):
    zip_path = "flag_" + str(1000-number) + ".zip"
    fp = zipfile.ZipFile(zip_path)
    for file in fp.namelist():
        fp.extract(file,"./",pwd=password.encode("utf-8"))
    fp.close()


def main():
    path = sys.path[0]            #当前脚本的运行目录

    for number in range(1,1001):
        print("Processing the "+ str(number) + "th archive.")
        #print(os.listdir('.'))   #显示当前目录下的所有文件
        morse_list = get_morse()
        password = get_pass(morse_list)
        unzip_file(path, number, password)
        path = "./flag"
        os.chdir(path)       #切换当前工作目录(进入flag子目录)

    fp = open('./flag', 'r')
    flag = fp.readlines()
    print(flag)
    fp.close()


if __name__ == "__main__":
    main()

解压后查看最后一个压缩包中包含HTB的字段(很多种方法,这里就不赘述)

答案:HTB{D0_y0u_L1k3_m0r53??}

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-02 07:12:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-02 07:12:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-02 07:12:04       82 阅读
  4. Python语言-面向对象

    2024-02-02 07:12:04       91 阅读

热门阅读

  1. 安装配置hive

    2024-02-02 07:12:04       56 阅读
  2. kafka

    2024-02-02 07:12:04       48 阅读
  3. Android 打包V1 / V2签名

    2024-02-02 07:12:04       54 阅读
  4. easyexcel实现相同内容的上下行合并

    2024-02-02 07:12:04       53 阅读
  5. 介绍 TensorFlow 的基本概念和使用场景。

    2024-02-02 07:12:04       50 阅读
  6. EXCEL VBA调用百度api识别身份证

    2024-02-02 07:12:04       51 阅读
  7. PyTorch与TensorFlow的安装与介绍

    2024-02-02 07:12:04       49 阅读
  8. Qt应用软件【协议篇】modbus-tcp示例

    2024-02-02 07:12:04       52 阅读
  9. Kafka客户端实战

    2024-02-02 07:12:04       53 阅读
  10. 考研经验总结——考试期间

    2024-02-02 07:12:04       54 阅读
  11. Linux内核--设备驱动(一)驱动的结构介绍

    2024-02-02 07:12:04       48 阅读
  12. 【嵌入式——C++】list(STL)

    2024-02-02 07:12:04       59 阅读