Exemple #1
0
def _send(k, p, sockfd, payload, flags=0):
    socket_handle = k.z.handles.get(sockfd)
    if socket_handle is None:
        k.logger.notice(f"Invalid socket fd 0x{sockfd:x}")
        return -1
    sock = socket_handle.socket
    sent_len = sock.send(payload, flags)

    if socket_handle.data.get("port", 0) == 53:
        target = dns.parse_dns_request(payload)
        if target is not None:
            k.print_info(f"DNS Request: {target}")
            k.z.network.add_attempted_connection(target, "sendto")

    return sent_len
Exemple #2
0
def sendto(k, p, args_addr):
    def print_buf(args):
        s = repr(bytes(p.memory.read(args.buf, size=args.len)))[2:-1]
        return f'buf=0x{args.buf:x} ("{s}")'

    def print_dst(args):
        socket_handle = k.z.handles.get(args.sockfd)
        if socket_handle is None:
            return "{0}=0x{1:x}".format("dest_addr", args.dest_addr)
        sock = socket_handle.socket
        sockaddr = bytes(p.memory.read(args.dest_addr, args.addrlen))
        (host, port) = get_host_and_port(sock.domain, sockaddr)
        return f"dest_addr=0x{args.dest_addr:x} ({host}:{port})"

    args = k._get_socketcall_args(
        p,
        "sendto",
        args_addr,
        [
            ("int", "sockfd"),
            ("const void*", "buf"),
            ("size_t", "len"),
            ("int", "flags"),
            ("const struct sockaddr*", "dest_addr"),
            ("socklen_t", "addrlen"),
        ],
        arg_string_overrides={
            "buf": print_buf,
            "dest_addr": print_dst
        },
    )
    socket_handle = k.z.handles.get(args.sockfd)
    if socket_handle is None:
        k.logger.notice(f"Could not find socket {args.sockfd}")
        return -1
    sock = socket_handle.socket
    sockaddr = bytes(p.memory.read(args.dest_addr, args.addrlen))
    (host, port) = get_host_and_port(sock.domain, sockaddr)
    payload = p.memory.read(args.buf, args.len)

    if socket_handle.data.get("port", 0) == 53:
        target = dns.parse_dns_request(payload)
        if target is not None:
            k.print_info(f"DNS Request: {target}")
            k.z.network.add_attempted_connection(target, "sendto")

    return sock.sendto(payload, (host, port), args.flags)