我有以下几点:
#define IPADDR "\xc0\x80\x10\x0a" /* 192.168.1.10 */
#define PORT "\x7a\x69" /* 31337 */然而,在我的一生中,我无法弄清楚十六进制值如何等于ASCII值。如何将其更改为不同的IP或端口号?
基本上,如何从IP获得\xc0\x80\x10\x0a,反之亦然?
简而言之,我正在看http://shell-storm.org/shellcode/files/shellcode-857.php,我想知道他们是如何到达的,以及那根长长的字符串。
谢谢
发布于 2021-12-21 00:35:32
这不是为了达到目的,它只是一种不同的方式来表达相同的东西:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define IPADDR "\xc0\x80\x10\x0a" /* not 192.168.1.10 */
/* but 192.128.16.10 */
#define PORT "\x7a\x69" /* not 31337 */
/* but 27002 */
#define c2ui(a) ((unsigned int)(unsigned char)a)
int main()
{
printf("\n%u.%u.%u.%u\n", c2ui(IPADDR[0]),
c2ui(IPADDR[1]),
c2ui(IPADDR[2]),
c2ui(IPADDR[3]));
printf("\n\\x%02x\\x%02x\\x%02x\\x%02x\n", c2ui(IPADDR[0]),
c2ui(IPADDR[1]),
c2ui(IPADDR[2]),
c2ui(IPADDR[3]));
union
{
uint8_t s_port[3];
uint16_t v_port;
} v;
memcpy(v.s_port, (uint8_t *)&PORT[0], sizeof(PORT));
printf("\nport: %u\n", v.v_port);
}除了我在示例代码中指出的描述中存在错误之外。相反,在端口的情况下存在一个问题,因为这个数字是正确的,这取决于程序运行的系统类型。例如,在我的系统中,要得到像描述中那样的值,我就必须将这两个字符反转。因此,对值使用这种格式并不是一个好主意。如果它写的是:
#define PORT 31337 /* 31337 */发布于 2021-12-21 00:51:51
有标准函数nthos/htonl/ntohl/htonl在网络和主机字节顺序之间转换16位和32位值(基本上是端口号和ipv4地址)。例如:
sockaddr_in addr;
addr.sin_addr = htonl(INADDR_LOOPBACK); // loopback address converted to network order
addr.sin_port = htons(31337); // convert port to network orderhttps://stackoverflow.com/questions/70428421
复制相似问题