编译netcat

下载软件netcat-0.7.1,拷贝到Linux系统并解压:

[yubo.wang@localhost netcat-0.7.1]$ mkdir build
[yubo.wang@localhost netcat-0.7.1]$ cd build/
[yubo.wang@localhost netcat-0.7.1]$ ../configure --host=arm-linux --prefix=$PWD CC=/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin/arm-hisiv300-linux-gcc
[yubo.wang@localhost netcat-0.7.1]$ make
[yubo.wang@localhost netcat-0.7.1]$ make install

[yubo.wang@localhost build]$ readelf -h bin/netcat 
ELF 头:
  Magic:  7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF32
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              EXEC (可执行文件)
  系统架构:                          ARM
  版本:                              0x1
  入口点地址:              0x9e3c
  程序头起点:              52 (bytes into file)
  Start of section headers:          97884 (bytes into file)
  标志:             0x5000202, Version5 EABI, soft-float ABI, <unknown>
  本头的大小:       52 (字节)
  程序头大小:       32 (字节)
  Number of program headers:         6
  节头大小:         40 (字节)
  节头数量:         33
  字符串表索引节头: 30
[yubo.wang@localhost build]$ readelf -d bin/netcat 

Dynamic section at offset 0x75fc contains 21 entries:
  标记        类型                         名称/值
 0x00000001 (NEEDED)                     共享库:[libc.so.0]
 0x0000000c (INIT)                       0x8d94
 0x0000000d (FINI)                       0xdfb8
 0x00000019 (INIT_ARRAY)                 0x175f0
 0x0000001b (INIT_ARRAYSZ)               4 (bytes)
 0x0000001a (FINI_ARRAY)                 0x175f4
 0x0000001c (FINI_ARRAYSZ)               4 (bytes)
 0x00000004 (HASH)                       0x8108
 0x00000005 (STRTAB)                     0x8898
 0x00000006 (SYMTAB)                     0x8368
 0x0000000a (STRSZ)                      684 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000003 (PLTGOT)                     0x176cc
 0x00000002 (PLTRELSZ)                   544 (bytes)
 0x00000014 (PLTREL)                     REL
 0x00000017 (JMPREL)                     0x8b74
 0x00000011 (REL)                        0x8b44
 0x00000012 (RELSZ)                      48 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x00000000 (NULL)                       0x0

只依赖一个动态libc库

~ # netcat --help
GNU netcat 0.7.1, a rewrite of the famous networking tool.
Basic usages:
connect to somewhere:  netcat [options] hostname port [port] ...
listen for inbound:    netcat -l -p port [options] [hostname] [port] ...
tunnel to somewhere:   netcat -L hostname:port -p port [options]

Mandatory arguments to long options are mandatory for short options too.
Options:
  -c, --close                close connection on EOF from stdin
  -e, --exec=PROGRAM         program to exec after connect
  -g, --gateway=LIST         source-routing hop point[s], up to 8
  -G, --pointer=NUM          source-routing pointer: 4, 8, 12, ...
  -h, --help                 display this help and exit
  -i, --interval=SECS        delay interval for lines sent, ports scanned
  -l, --listen               listen mode, for inbound connects
  -L, --tunnel=ADDRESS:PORT  forward local port to remote address
  -n, --dont-resolve         numeric-only IP addresses, no DNS
  -o, --output=FILE          output hexdump traffic to FILE (implies -x)
  -p, --local-port=NUM       local port number
  -r, --randomize            randomize local and remote ports
  -s, --source=ADDRESS       local source address (ip or hostname)
  -t, --tcp                  TCP mode (default)
  -T, --telnet               answer using TELNET negotiation
  -u, --udp                  UDP mode
  -v, --verbose              verbose (use twice to be more verbose)
  -V, --version              output version information and exit
  -x, --hexdump              hexdump incoming and outgoing traffic
  -w, --wait=SECS            timeout for connects and final net reads
  -z, --zero                 zero-I/O mode (used for scanning)

Remote port number can also be specified as range.  Example: '1-1024'

问题

1、有时候发送数据后命令不能退出

netcat -lp 1234

echo "hello" | nc 192.168.10.254 1234,正常情况下发送数据后此命令应该要退出的,但是一旦不能退出后面不管做什么操作都不能退出了,这是为何??

 

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,针对您的问题,我可以提供以下解答: 1. 静态编译netcat 在Linux系统上,使用静态编译的方式编译netcat,可以使得生成的二进制文件不依赖于系统的动态链接库,方便在其他系统上使用。具体步骤如下: ``` # 下载最新版的netcat源码 wget https://downloads.sourceforge.net/project/netcat/netcat/0.7.1/netcat-0.7.1.tar.gz # 解压源码 tar -xvf netcat-0.7.1.tar.gz # 进入源码目录 cd netcat-0.7.1 # 配置静态编译选项 ./configure --disable-shared --enable-static # 编译 make # 安装 make install ``` 2. 交叉编译netcat在路由器上使用 如果您想在路由器上使用netcat,需要进行交叉编译。具体步骤如下: ``` # 下载路由器的交叉编译工具链 wget http://downloads.openwrt.org/releases/18.06.2/targets/ar71xx/generic/openwrt-sdk-18.06.2-ar71xx-generic_gcc-7.3.0_musl.Linux-x86_64.tar.xz # 解压交叉编译工具链 tar -xvf openwrt-sdk-18.06.2-ar71xx-generic_gcc-7.3.0_musl.Linux-x86_64.tar.xz # 进入交叉编译工具链目录 cd openwrt-sdk-18.06.2-ar71xx-generic_gcc-7.3.0_musl.Linux-x86_64 # 配置交叉编译环境变量 export STAGING_DIR=`pwd`/staging_dir export PATH=$PATH:$STAGING_DIR/toolchain-mips_24kc_gcc-7.3.0_musl/bin # 下载最新版的netcat源码 wget https://downloads.sourceforge.net/project/netcat/netcat/0.7.1/netcat-0.7.1.tar.gz # 解压源码 tar -xvf netcat-0.7.1.tar.gz # 进入源码目录 cd netcat-0.7.1 # 配置交叉编译选项 ./configure --host=mips-openwrt-linux --disable-shared --enable-static # 编译 make # 将编译好的二进制文件拷贝到路由器上 scp nc root@192.168.1.1:/usr/bin/ ``` 上面的步骤是以OpenWrt路由器为例进行说明的,如果您使用的是其他型号的路由器,需要根据实际情况进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值