Network attack

原理:JSON格式

基本概念

JSON是一种独立于编程语言的数据格式。更容易编写和阅读,同时便于机器解析和生成。

数据结构

JSON的数据主要由两种基础结构:

1、键值对:
·使用大括号{}包裹;
·键和值之间用冒号,分隔;
·多个键值之间用逗号,分隔;
·键必须使用双引号""包裹;
·值可以是字符串、数字、布尔值、null、数组、或对象。

{
    "name": "ming",
    "age": 20
}

2、数组:
·使用[]包裹;
·可以包含多种元素,同样是逗号隔开;
·元素可以是基本类型也可以是对象或者数组;

{
    "student": [
        {"name": "Alice", "age": 18}
    ]
}

解题

题目

请在端口 11112 上连接到 socket.cryptohack.org 。然后发送一个 JSON 对象,该对象的键为 buy ,值为 flag 。

解题

1、命令交互

laiyi@LAPTOP-AGIFJB2L:~$ nc socket.cryptohack.org 11112
Welcome to netcat's flag shop!
What would you like to buy?
I only speak JSON, I hope that's ok.

{"buy": "flag"}
{"flag": "crypto{sh0pp1ng_f0r_fl4g5}"}

2、脚本
windows

import socket, json

HOST = "socket.cryptohack.org"
PORT = 11112

s = socket.create_connection((HOST, PORT))

def recv_line():
    buf = b""
    while not buf.endswith(b"\n"):
        buf += s.recv(1)
    return buf.decode()

def recv_json():
    return json.loads(recv_line())

def send_json(obj):
    s.sendall((json.dumps(obj) + "\n").encode())


for _ in range(4):
    print(recv_line())

send_json({"buy": "flag"})
print(recv_json())

Linux_pwntools

#!/usr/bin/env python3

from pwn import * # pip install pwntools
import json

HOST = "socket.cryptohack.org"
PORT = 11112

r = remote(HOST, PORT)


def json_recv():
    line = r.readline()
    return json.loads(line.decode())

def json_send(hsh):
    request = json.dumps(hsh).encode()
    r.sendline(request)


print(r.readline())
print(r.readline())
print(r.readline())
print(r.readline())

request = {
    "buy": "flag"
}
json_send(request)

response = json_recv()

print(response)
posted @ 2026-09-26 20:32  laiyi一一  阅读(2)  评论(0)    收藏  举报