Category: Network

  • 正常情况下TCP/IP协议中SYN握手大致上如此:

    正常情况下TCP/IP协议中SYN握手大致上如此:

    1. A(发起者)发送一个SYN给B(接收者)
    2. B回复SYN-ACK给A
    3. A回复ACK给B
    4. 连接成功!

    这个过程的缺陷是,如果A是有恶意的来源,始终不停的发送SYN给B,那么B就会不停的建立起空连接(未完成的连接)等待A的ACK响应,只要A不回应,B的空连接就会不断的消耗资源,直至无法响应。

    这个缺陷事实上不是操作系统级别、防火墙级别的缺陷,而是来自于TCP/IP协议本身的设计缺陷。

    看了一下NetScreen的Screen安全策略中有针对它设计的SYN COOKIE设置。

    个人理解下来这是一个很讨巧的方法,但是略显笨拙:

    1. NS之外的A发送了一个SYN请求给内网的B
    2. NS截获了这个请求,没有直接将数据包转发给B,而是自己生成了一个假冒的SYN_ACK包回复给A
    3. A回复了ACK,成功完成握手
    4. NS将之前的SYN请求发送给B
    5. B发送SYN-ACK
    6. NS回复ACK
    7. NS搭建A到B的正式通道

    这种方式类似于中间人的方式实现连接,一定程度上是可以保护B不受攻击的侵扰。但事实上如果这时的A有足够的资源,完全可以让NetScreen建立的空连接达到无法响应的程度,这样实现的效果反而远远大于直接对B发起的攻击。

    对于类似的方法,Netscreen没有响应的设置,相应的文档上也没有给出解释。个人认为,NS应该是有一种判断机制,比如说时间或者频率。正常情况下是允许ACK回复延时的,但延时到了一定程度,或者这个来源不停的建立这种通信达到一个阀值,NS将会启动处理机制将A拉黑,同时关闭所有与A有关的连接。

    总的来说,SYN-ACK-ACK攻击属于不对等攻击,与DDOS,泪滴等攻击一样,发起攻击的成本要远远低于预防攻击的成本,这是TCP/IP的缺陷,只要不放弃TCP/IP,这样的攻击就会一直存在。而且防止前提必须是“已经受到了攻击”之后,即只能医治,无法预防。

  • mac linux usb console线连交换机

    一般usb转console线的参数如下

     波特率 9600
     数据位 8
     奇偶校验None
     停止位 1

    osx自带screen命令,usb console线插在mac上之后,在/dev/下会认到这个线的编号。

    /dev/cu.usbserial-xxxxxx
    /dev/tty.usbserial-xxxxxx

    接下来执行下面的命令即可,9600是波特率

    screen /dev/tty.usbserial-A4006Jvo 9600

    补充:

    linux 下使用 screen 连接 console

    通过 lsusb 查看插上去的线能被识别到,然后默认到 com1 口连接,如 /etc/ttyS0 ,使用如下命令接到交换机。

    screen /dev/ttyS0
  • tcpdump使用方法

    tcpdump是linux命令行下常用的的一个抓包工具,抓包的目的是分析问题。

    tcpdump -i eth0 -nn 监听eth0,-nn表示以ip和port方式显示包,不将ip转为主机名,这种在装B的时候可以刷屏,意义不大

    所以要实现更精细化的抓包还是需要加更多的参数,使用man tcpdump | less -Ip examples可以查看手册中的例子。以下是常用的例子

    查看所有网卡

    tcpdump -D

    抓取具体协议的包

    tcpdump -i eth0 -nn 'udp'
    tcpdump -i eth0 -nn 'tcp'
    tcpdump -i eth0 -nn 'icmp'

    抓取192.168.1.233的包

    tcpdump -i eth0 -nn 'host 192.168.1.233'

    抓取从192.168.1.233发送的包

    tcpdump -i eth0 -nn 'src host 192.168.1.233'

    抓取发送到192.168.1.233的包

    tcpdump -i eth0 -nn 'src host 192.168.1.233'

    多种参数用and连接,如

    tcpdump -i eth0 -nn 'tcp port 80 and host 192.168.1.233'

    使用tcpdump截取HTTP包会很方便

    tcpdump 过滤 HTTP GET

    tcpdump -s 0 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'

    tcpdump 过滤 HTTP POST

    tcpdump -s 0 -A 'tcp dst port 80 and (tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354)'

    tcpdump -e 显示以太网数据帧

    tcpdump -v 显示进行的分组交换

    tcpdump 查看 http 响应全部报文

    tcpdump -A -vvvv -s 9999 -i eth0 port 80

    查看HTTP的请求和反回头和内容,详见https://sites.google.com/site/jimmyxu101/testing/use-tcpdump-to-monitor-http-traffic

    tcpdump -A -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
    tcpdump -X -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

    1. To monitor HTTP traffic including request and response headers and message body:

    tcpdump -A -s 0 ‘tcp port 80 and (((ip[2:2] – ((ip[0]&0xf)<<2)) – ((tcp[12]&0xf0)>>2)) != 0)’

    2. To monitor HTTP traffic including request and response headers and message body from a particular source:

    tcpdump -A -s 0 ‘src example.com and tcp port 80 and (((ip[2:2] – ((ip[0]&0xf)<<2)) – ((tcp[12]&0xf0)>>2)) != 0)’

    3. To monitor HTTP traffic including request and response headers and message body from local host to local host:

    tcpdump -A -s 0 ‘tcp port 80 and (((ip[2:2] – ((ip[0]&0xf)<<2)) – ((tcp[12]&0xf0)>>2)) != 0)’ -i lo

    4. To only include HTTP requests, modify “tcp port 80” to “tcp dst port 80” in above commands

    5. Capture TCP packets from local host to local host

    tcpdump -i lo

    tcpdump flag解读

    tcpdump-data-flags

    TCP Flag Flag in tcpdump Flag Meaning
    SYN s Syn packet, a session establishment request. The first part of any TCP connection.
    ACK ack Ack packet, used to acknowledge the receipt of data from the sender. May appear in conjunction with other flags.
    FIN f Finish flag, used to indicate the sender’s intention to terminate the connection to the receiving host.
    RESET r Indicates the sender’s intention to immediately abort the existing connection.
    PUSH p Signals the immediate push of data from the sending host to the receiving host. For interactive applications such as telnet, the main issue is the quickest response time, which this “push” flag signals.
    URGENT urg Urgent data should take precedence over other data. For example, a Ctrl-C to terminate a FTP download.
    Placeholder 0 If the connection does not have a syn, finish, reset, or push flag set, this placefolder flag will be found after the destination port. Note that it also appears in conjunction with the ack flag.

    tcpdump读出来的信息可以保存方便查看和分析
    保存pcap信息,可以用WireShark来查看

    tcpdump -i vmbr1 -nn -vv -tttt -s 65535 -w tcpdump.pcap

    如果担心文件过大可以加 -C 跟数字,当文件达到这个值(MB)之后,会新生成tcpdump.pcap.2

    抓取 sql 语句

    tcpdump -i bond0 -s 0 -l -w -  | strings | perl -e '
    while(<>) { chomp; next if /^[^ ]+[ ]*$/;
        if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i)
        {
            if (defined $q) { print "$q\n"; }
            $q=$_;
        } else {
            $_ =~ s/^[ \t]+//; $q.=" $_";
        }
    }'
    

    查看保存文件的格式

    # file tcpdump.pcap
    tcpdump.pcap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 65535)

    对于保存的文件可以用-r读取,相当于对之前的抓取的过程进行回放。

    tcpdump -ttttnnr tcpdump.pcap
    tcpdump -qns 0 -X -r tcpdump.pcap
    tcpdump -e -r tcpdump.pcap

    wireshark filter

    重传

    tcp.analysis.retransmission
    

    过滤 tcp stream

    tcp.stream eq 1
    
  • 思科路由器交换机使用ssh方式连接

    进入配置模式

    configure terminal

    一、设置enable密码

    enable secret password

    enable secret 5 $1$7W0A$UTAhixRjHMbE0kHPWZNMJ0

    二、给交换机命名

    hostname switch

    三、配置域名

    ip domain-name test.com

    四、启用AAA,并产生rsa密钥对

    aaa new-model
    crypto key generate rsa

    R1(config)#crypto key generate rsa
    The name for the keys will be: R1.router.jpuyy.com
    Choose the size of the key modulus in the range of 360 to 2048 for your
    General Purpose Keys. Choosing a key modulus greater than 512 may take
    a few minutes.

    How many bits in the modulus [512]: 1024
    % Generating 1024 bit RSA keys, keys will be non-exportable…[OK]

    注:rsa默认为512bits,建议采用768bits以上的长度,这样可开启对sshv2的支持

    五、配置用户名和口令

    username cisco password cisco

    六、配置登录方式为SSH。注意要将0-15全部配置为SSH方式,不然telnet仍可访问。

    line vty 0 4
     transport input ssh
    line vty 5 15
    transport input ssh

    最后可通过以下命令查看显示SSH配置信息

    R1#show ip ssh

    SSH Enabled – version 1.99
    Authentication timeout: 120 secs; Authentication retries: 3

  • 使用moto xt610作为modem的方法

    我这里使用的是上海电信的evdo rev.A网,3G。经过操过可以将电脑与手机通过usb连接,并使用3G流量上网。

    方法一:

    在ubuntu和windows下均可,在手机上

    设置->应用程序->开发,勾选USB调试;

    设置->无线和网络->绑定与便携式热点->勾选usb绑定;

    这里电脑已经多出来一个网卡可以上网了,分配的ip即是热点设置中dhcp分配的。

    方法二:

    只在windows下,安装motorola的驱动

    http://www.motorola.com/staticfiles/Support/Experiences/Global_Drivers/USB_Drivers_bit_4.7.1.zip

    连接好usb后,选择usb连接模式是“摩托罗拉手机门户”

    在网络设置处,新建拨号,默认会选中Motorola usb modem,拨号号码为#777,用户名密码均为card,连接后电脑即可上网。

  • cisco 2960s常用命令

    查看运行中的配置

    show running-config

    设备的型号,运行时间,固件

    show version

    其中

    Processor board ID 或 System serial number 为设备出厂时候的序列号

    show version | in uptime
    uptime is 12 weeks, 3 days, 20 hours, 17 minutes

    查看mac地址表

    show mac address-table

    查看具体的mac地址

    show mac address-table address 0008.00ff.fc04

    设置交换机的vlan ip信息,在configure terminal模式下

    ip address 192.168.8.222 255.255.255.0
    ip default-gateway 192.168.8.1

    查看当前路由器的时间

    show clock

    查看日志信息

    show log

    查看接口的信息,很全,后面可以接具体的项

    show interfaces
    show interfaces description查看接口up or down
    show interfaces status 快速查看接口

    查看cdp邻居

    show cdp neighbors

    查看vlan信息

    show vlan

    设置时间

    clock set 16:51:00 20 Aug 2013

    查看学习到的arp表

    show ip arp

    过滤,类似于grep

    show arp | include 0010.d1aa.0224

    查看内存情况,可以看到内存有70MB

    show processes memory
    
    Processor Pool Total:   73922040 Used:   26257284 Free:   47664756
    
    I/O Pool Total:   14680064 Used:   12235212 Free:    2444852
    
    Driver te Pool Total:    1048576 Used:         40 Free:    1048536
    

    查看 cpu 使用情况

    show processes cpu sorted
    CPU utilization for five seconds: 9%/0%; one minute: 9%; five minutes: 9%

    输出过多时,可以不折叠

    terminal length 0

    清理单条arp信息

    clear arp 10.10.0.249
    #clear arp ?
     A.B.C.D IP address             # 清理单条记录
     counters Clear ARP counters         #重置计数器
     interface Clear the entire ARP cache on the interface  # 清空整个arp缓存
     vrf Clear entries for a VPN Routing/Forwarding instance

    配置Telnet密码的过程如下.copy自:http://network.51cto.com/art/201007/212927.htm

    第1步,进入全局配置模式.

    Cisco# configure terminal

    第2步,输入Telnet进程号,进入Line配置模式.在一台交换机和路由器上,最多可以实现16个Telnet进程,方便多个用户同时查看和管理.”0 15″表明配置所有可能的16个进程.

    Cisco(config)# line vty 0 15

    第3步,指定Telnet密码.Telnet密码设置要求与Enable相同.

    Cisco(config)# password password

    第4步,返回特权模式.

    Cisco(config)# end

    第5步,保存配置Telnet密码最后的修改.

    Cisco# copy running-config startup-config

    改主机名也在configure terminal里

    hostname yourhostname