当前位置:网站首页>A penetration test of c/s Architecture - Request encryption, decryption and test
A penetration test of c/s Architecture - Request encryption, decryption and test
2022-06-24 07:27:00 【Xiaoxiang Xin'an】
Statement : Most of the official account is from the author's daily notes. , A few articles are also reproduced by authorship of the original author and other official account. , unaccredited , It is strictly prohibited to reprint , If you want to reprint , Contact and talk . Do not use the related technology in the article to engage in illegal testing , Any adverse consequences arising from this are not related to the author and the official account. . |
|---|
0x01 summary
The target site is http://www.example.com, The official website provides api Using document , However, no vulnerability was found after testing , Catalog 、 No usable points are found in port scanning . After that, I found that the official website provides client-side download , So we tested it .
0x02 Information gathering
First, grab the package of the client , Use Fiddler and BurpSuite Can't catch it , It is doubtful that it is HTTP agreement , use WireShark To see if it is practical HTTP agreement , But packets are hard to replay .
Here we finally use WSExplorer Grab the package of the specified process , Successfully grab the communication data , Here's the data , The green one is the request package , The red one is the response package .
The packet is divided into two parts , One is the request line and the request header .
One is the request body .
Put them together and put them in BurpSuite To replay packets
0x03 Testing process
You can see that the request packet is encrypted and then transmitted , The returned response package is also encrypted . But encryption and decryption are always carried out on the client , So you can start with analyzing the client .
Use Exeinfo PE Check the shell , It is known that .NET frame C# Developed programs .
have access to dnspy, in the light of .NET Reverse engineering tools for programs , Analyze the encryption and decryption of the client . After opening, I found that the names of classes and methods are irregular numbers and letters , The code is confusing .
Confused code does not use reading analysis , You can use De4Dot Try anti aliasing , Support many kinds of source code that have been confused by encryption tools . You can get the program after anti aliasing origin-cleaned.exe
de4dot-x64.exe origin.exe
Drag the anti aliased program into dnspy see , You can see that the basic has been restored , Improved readability .
Because its communication adopts HTTP agreement , Another class named HttpHelper, Follow up analysis , The code doesn't see one more Post function , Suspected of encrypting data and initiating Post Requested method , Pictured .
Called MM.Encrypt() Encrypt the requested parameters , Follow up method , It is found that the key encryption function should be MM Under class test05 function .
Lower breakpoint , Verify that the program calls this function to encrypt and transmit , I made a breakpoint between the plaintext and the ciphertext .
F5 Start the program , Enter the account and password test123456, Sign in .
The program stops at a breakpoint , The account number I entered is included in the plaintext test123456 and md5 Encrypted password .
release , Get encrypted content , It can be determined that the encryption function here is called .
Then it is confirmed that the response packet decryption calls MM Under class test06 function , Request package encryption function test05 And the response packet decryption function test06 All calls Dll The corresponding function in .
Here, encryption and decryption call two sets of methods , The decryption function cannot be used to decrypt the encrypted data of the request packet . For testing purposes , And fast encryption and decryption , Deduct the encryption and decryption functions , Also called Dll The function in , Compile into a separate program , In this way, there is no need to analyze the algorithm .
What I'm using here is SharpDevelop Compilation of , Use Visual Studio Always report a mistake …
public static string decryptResponse(string cipher){
byte[] bytes = Encoding.UTF8.GetBytes(cipher);
byte[] array = new byte[bytes.Length + 128];
int count = Program.test06(ref bytes[0], ref array[0]);
string text = Encoding.UTF8.GetString(array, 0, count);
return text;
}
public static string encryptRequest(string plain){
byte[] bytes = Encoding.UTF8.GetBytes(plain);
int num = bytes.Length * 2 + 128;
if(num<32){
num = 64;
}
byte[] array = new byte[num];
int num2 = 0;
num2 = test05(ref bytes[0], ref array[0]);
string result = Encoding.UTF8.GetString(array, 0, num2);
return result;
}encryption
Decrypt
Reuse Python Of Flask The framework writes a proxy forwarder locally , Convenient in BurpSuite Replay test in .
from flask import request, Flask
from urllib.parse import quote
import requests
import os
headers = {
'User-Agent': 'Mozilla',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'gzip, deflate',
}
app = Flask('example')
@app.route('/example', methods=['POST'])
def proxy():
form = request.form
request_plain = ''
for key in form:
request_plain += '&{}={}'.format(key, form[key])
response_plain = test(request_plain)
return response_plain
def encrypt(filename):
encrypt_cmd = 'crypto.exe -encrypt {}'.format(filename) # Content to encrypt Read from file
result = os.popen(encrypt_cmd) # perform exe
request_cipher = quote(result.read()) # Encrypted content After a url Coding handle + Number Turn into %2B Only the server can recognize
return request_cipher
def decrypt(filename):
decrypt_cmd = 'crypto.exe -decrypt {}'.format(filename) # What to decrypt Read from file
result = os.popen(decrypt_cmd) # perform exe
response_plain = result.read() # Read the decrypted content
return response_plain
def test(request_plain):
url = 'http://example.com/api/'
plain_txt = 'plain.txt'
with open(plain_txt, 'w') as f1:
f1.writelines(request_plain) # Store plaintext to plain.txt
request_cipher = encrypt(plain_txt) # Encrypt plaintext
response = requests.post(url=url, data=request_cipher, headers=headers) # Send a request
cipher_txt = 'cipher.txt'
with open(cipher_txt, 'w') as f2:
f2.writelines(response.text) # Store ciphertext to cipher.txt
response_plain = decrypt(cipher_txt) # Decrypt the ciphertext
return response_plain
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9999, debug=True)The process is as follows :
- Send clear text packets locally to the agent
- The agent received the request packet
- The caller encrypts the request package
- Forward the encrypted packet to the server
- The caller decrypts the contents returned by the server
- Return plaintext data to local
The interface is the same for each request , Only the parameters in the request body are changed . stay CodeService There is clear text for all interfaces in , Extract it all .
Can be normally in BurpSuite Intermediate testing ~
Finally, it is successfully found in an interface SQL Inject .
Source of the article :CSDN Blog , Original address :
https://blog.csdn.net/qq_32727277/article/details/102783316
边栏推荐
- Buuctf misc grab from the doll
- The P2V and V2V software starwind converter is really easy to use
- Tencent host security captures Yapi remote code execution 0day vulnerability for wild exploitation. The attack is spreading and can be intercepted by firewall
- Canal installation configuration
- 0 foundation a literature club low code development member management applet (6)
- [DDCTF2018](╯°□°)╯︵ ┻━┻
- In JS, the regular expression verifies the hour and minute, and converts the input string to the corresponding hour and minute
- Tutorial on simple use of Modbus to BACnet gateway
- PCL calculates the area of a polygon
- [DDCTF2018](╯°□°)╯︵ ┻━┻
猜你喜欢

Huawei cloud database advanced learning

Dichotomous special training

Accessing user interface settings using systemparametersinfo

捏脸师: 炙手可热的元宇宙造型师

【Vulhub靶场】】zabbix-SQL注入(CVE-2016-10134)漏洞复现

Ultra wideband pulse positioning scheme, UWB precise positioning technology, wireless indoor positioning application
![[Proteus] Arduino uno + ds1307+lcd1602 time display](/img/96/d8c1cacc8a633c679b1a58a1eb8cb9.png)
[Proteus] Arduino uno + ds1307+lcd1602 time display

简单使用Modbus转BACnet网关教程
![[image fusion] image fusion based on directional discrete cosine transform and principal component analysis with matlab code](/img/21/a5a973f06ea002755a8a2a4431dcd8.png)
[image fusion] image fusion based on directional discrete cosine transform and principal component analysis with matlab code

What is the mentality of spot gold worth learning from
随机推荐
二分专题训练
简单使用Modbus转BACnet网关教程
[WordPress website] 5 Set code highlight
【信号识别】基于深度学习CNN实现信号调制分类附matlab代码
RDD basic knowledge points
In JS, the regular expression verifies the hour and minute, and converts the input string to the corresponding hour and minute
0 foundation a literature club low code development member management applet (5)
Record the problem location experience when an application is suddenly killed
Dichotomous special training
基因检测,如何帮助患者对抗疾病?
Huawei Cloud Database Advanced Learning
(CVE-2020-11978)Airflow dag中的命令注入漏洞复现【vulhub靶场】
现货黄金有哪些值得借鉴的心态
[DDCTF2018](╯°□°)╯︵ ┻━┻
0 foundation a literature club low code development member management applet (4)
bjdctf_2020_babystack
MFC使用控制台时 项目路径中不能有空格和中文,否则会报错误 LNK1342 未能保存要编辑的二进制文件的备份副本等
Mysql---三张表(student,课程,分数) 查询课程为数学的学生姓名,编号,成绩
In the era of industrial Internet, there are no more centers in the real sense, and these centers just turn tangible into intangible
[signal recognition] signal modulation classification based on deep learning CNN with matlab code