1.设置用户名和密码
提问:为每个单独的人员设置不同的用户名和密码
回答:
Router1(config)#username NAME password WORD
Router1(config)#username NAME nopassword  //创建username不使用密码
Router1(config)#aaa new-model
Router1(config)#aaa authentication login local_auth local
Router1(config)#line vty 0 4
Router1(config-line)#login authentication local_auth
 
注释:
  • 不推荐使用没有密码的username,会产生安全问题
  • 设置单独的用户名和密码在日志中会显示谁做了修改,比如%SYS-5-RELOAD: Reload requested by kdooley on vty0 (172.25.1.1)
  • 在username这个命令里面还有一个autocommand的选项,实现登录以后自动执行某个特定的命令的作用,然后自动推出。下面的例子就是一个用户名为NAME 无密码,登录以后显示完端口状态就自动退出的例子
    Router1(config)#aaa new-model
    Router1(config)#aaa authentication login default local
    Router1(config)#aaa authorization exec default local
    Router1(config)#username NAME nopassword noescape
    Router1(config)#username NAME autocommand show ip interface brief
    这里的noescape防止用户使用escape来进入路由器的EXEC模式,强烈推荐使用
2.加密密码
提问:加密密码从而在配置文件中不明文显示
回答:
Router1(config)#enable password oreilly
Router1(config)#line vty 0 4
Router1(config-line)#password cookbook
Router1(config-line)#line con 0
Router1(config-line)#password cookbook
Router1(config-line)#line aux 0
Router1(config-line)#password cookbook
Router1(config)# service password-encryption
 
注释:
  • 这种加密方式很弱,很容易被破解
3.一种更好的密码加密技术
提问:使用强度高的加密方式而不是思科缺省的加密技术
回答:
Router1(config)# enable secret ORAbooks
在IOS 12.2(8)T后也可以对username的密码做高强度的加密
Router1(config)# username ijbrown secret oreilly
 
注释:
  • 由于这种加密方式使用的是MD5所以破解难度相对增大了
  • 密码设定正常没有?,不过可以通过Control v+?的方式来输入
4. 移去配置文件中的密码信息
提问:不想在配置文件中显示密码
回答:使用脚本略去
 
注释:
  • 简单的用show tech命令也可以
5.解密思科的弱密码
提问:破解思科缺省的密码算法
回答:使用脚本略去
 
注释:
  • 可以使用BOSON网站上的免费工具
6.显示当前登录用户
提问:显示当前登录设备的用户
回答:
Router1# show users(who)
 
注释:
  • Router1#show users all 显示所有登录设备的用户线程
  • finger @Router1 远程查看登录用户
7.发信息给其它用户
提问:试图发送信息给登录在同一设备的其它用户
回答:
Router1# send *
Router1# send console 0
Router1# send vty 2
Router1# send 66

注释:
  • 很好用的特性,比如当你重启的时候需要告诉别人,文本信息^+Z结束
8.修改可用VTY数目
提问:增加或者减少可登录用户的数目
回答:
Router1(config)#line vty 0 9

注释:
  • 缺省可登录vty数目为5(0-4),不能删除
  • 对于增加的VTY线程可以使用no line vty x(x>4) 删除
  • 不能单独添加vty线程,若line vty 9,则自动创建vty 5-9
  • 同样不能删除单独的vty线程,若no line vty 9,则自动删除vty 5-9
9.修改VTY的超时时长
提问:修改超时避免用户登录超时被系统断开
回答:
Router1(config)# line vty 0 4
Router1(config-line)# exec-timeout 0 0 (exec-timeout 240 0)

注释:
  • 缺省情况下用户10分钟空闲就会被踢掉系统,0 0可以永不超时,第一个0是分钟,最长35791分钟(24天),第二个0是秒
  • 同时为了防止有些用户掉死但是还占用vty端口的情况,建议使用下面命令来防止:
  • Router1(config)#service tcp-keepalives-in //保证Tcp建立的入连结是活动的,如果路由器或交换机没有收到远程系统的响应,会自动关闭连接
  • 使用show terminal命令查看当前线程的不活动时间
10.限制用户登录可以使用的协议
提问:只允许用户用特定的协议来进行系统登录
回答:
Router1(config)# line vty 0 4
Router1(config-line)# transport input telnet

注释:
  • 缺省情况下除了可以telnet登录,还支持以下协议登录lat,pad,v120,lapb-ta,rlogin,ssh
11.配置用户登录可用总时长
提问:对用户登录总时长进行限制,不论是否在空闲还是活动
回答:
Router1(config)# line vty 0 4
Router1(config-line)# absolute-timeout 5
Router1(config-line)# logout-warning 30

注释:
  • 建议登出警告不小于10分钟
12.部署警示性信息
提问:设置登录时显示的警示性信息
回答:
Router1(config)# banner exec  # This is an exec banner #
Router1(config)# banner login # This is a login banner #
Router1(config)# banner motd  $ This is a motd banner $

注释:
  • Motd为Message of the Day,每天的信息,很少使用
  • Login banners主要用来显示一个安全警告
  • 一个好的登录警告应该包括下面几点:
    1.告诉企图登录的人,没有经过授权使用本路由器是不允许的
    2.告诉企图登录的人,所有的操作都是被监控的
    3.告诉企图登录的人,没进过授权的操作是不合法的,这些记录将会被用来进行法律行动
    4.最重要的是,登录警告中,不能透露有关路由器的敏感的信息为***提供方便
下面是一个FBI的路由器登录banner做参考:
Router1(config)# banner login #
Enter TEXT message.    End with the character '#'.
 
+--------------------------------------------------------------------+
|                                WARNING                             |
|                                -------                             |
| This system is solely for the use of authorized users for official |
| purposes.    You have no expectation of privacy in its use and to  |
| ensure that the system is functioning properly, individuals using  |
| this computer system are subject to having all of their activities |
| monitored and recorded by system personnel. Use of this system     |
| evidences an express consent to such monitoring and agreement that |
| if such monitoring reveals evidence of possible abuse or criminal  |
| activity, system personnel may provide the results of such         |
| monitoring to appropriate officials.                               |
+--------------------------------------------------------------------+
#
Router1(config)# end
13.在特定端口禁用Banners显示
提问:aux口用于modem连接,为了避免出现问题希望关闭banner显示
回答
Router1(config)# line aux 0    
Router1(config-line)# no motd-banner
Router1(config-line)# no exec-banner

注释:
  • 不能在线程上关闭login banner,所以如果你要达到这个目的,你可以使用motd banner代替login banner
14.禁用Line登录
提问:禁止在AUX或者Line端口进行设备登录
回答:
禁止在AUX进行设备登录
Router1(config)# line aux 0
Router1(config-line)# transport input none
Router1(config-line)# no exec
Router1(config-line)# exec-timeout 0 1
Router1(config-line)# no password
Router1(config-line)# exit
禁止在Line端口进行设备登录
Router1(config)# access-list 98 deny any log
Router1(config)# line vty 0 4
Router1(config-line)# transport input none
Router1(config-line)# exec-timeout 0 1
Router1(config-line)# no exec
Router1(config-line)# exit

注释:
  • transport input none 命令阻止反向TELNET到这个网络
    no exec 命令阻止端口运行EXEC模式会话
    no password 强制路由器清除线程上的密码,用户即使连接了也不能进行认证
  • 从console口来恢复密码很容易,所以推荐将路由器放在安全的地方,物理安全很重要
  • 你可以使用本地认证(local authentication)或AAA来代替直接在线程下配置密码
15.为管理员保留特定的登录端口
提问:防止所有的登录端口都被占用,为管理员留一个后门
回答
你可以为你自己保留一个VTY端口来登录路由器
Router1(config)# access-list 9 permit 172.25.1.1
Router1(config)# line vty 4
Router1(config-line)# access-class 9 in
或者使用rotary命令更改telnet登录的端口,来增加安全性
Router1(config)# access-list 9 permit 172.25.1.1
Router1(config)# line vty 5 7
Router1(config-line)# rotary 25
Router1(config-line)# access-class 9 in
 
注释:
  • 在使用第二种rotary命令时就相应的改变登录时的端口号码,不是缺省的23,而是3000+rotary的号码25=3025
  • 可以使用show line vty 来查看rotary和access-class相关信息
16.限制特定地址的Telnet登录 
提问:只允许特定的机器进行Telnet登录
回答:
Router1(config)#access-list 99 permit 172.25.1.0 0.0.0.255
Router1(config)#access-list 99 deny any log              
Router1(config)#line vty 0 4
Router1(config-line)#access-class 99 in
 
注释:
  • 推荐使用access-class来保证只有授权用户才能通过VTY来访问路由器
17.对Telnet访问进行日志记录
提问:记录每次telnet的日志
回答:
Router1(config)# access-list 90 permit any log
Router1(config)# line vty 0 4
Router1(config-line)# access-class 90 in
 
注释:
  • 需要注意的是不管登录成功还是失败,在日志中都是显示的permitted
    %SEC-6-IPACCESSLOGS: list 90 permitted 172.25.1.1 1 packet
18.设置发起Telnet的源地址
提问:有时对端设备有安全设置只允许特定的地址对外发起telnet请求
回答:
设置为对外发起的TELNET设置一个统一的IP源地址
Router1(config)# ip telnet source-interface loopback0
或者为某一个特定的telnet目的设置IP源地址
Router1# telnet 172.25.1.5 /source-interface loopback0
 
注释:
  • 缺省情况路由器会使用到目的地的端口来做Telnet的源地址
19.自动登录
注释:
  • 使用脚本略去,其实用SecueCRT很容易设定
20.使用SSH登录
提问:启用SSH这种加密的登录方式
回答:
Router1(config)# hostname Router1
Router1(config)# ip domain-name neoshi.net
Router1(config)# crypto key generate rsa
The name for the keys will be: Router1.oreilly.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 RSA keys ...
[OK]

Router1(config)#
Jun 27 15:04:15: %SSH-5-ENABLED: SSH 1.5 has been enabled
Router1(config)# ip ssh time-out 120
Router1(config)# ip ssh authentication-retries 4
 
注释:
  • 配置步骤:
    1.确认你运行的IOS版本大于12.1(1)T
    2.确认你运行的IOS版本包含IPSec特性(DES或3DES,最好3DES)
    3.配置本地认证(local authentication)或AAA,SSH不支持默认VTY密码加密
    4.配置路由器名,不能为Router
    5.用ip domain-name NAME命令在路由器上配置域名
    6.用crypto key negerate rsa命令产生一个SSH主机密钥,密钥长度从360 bits到2048 bits,密钥越长越安全,但影响路由器性能,不推荐使用短于1024 bits的密码。
  • 可以使用crypto key zeroize rsa命令删除密钥
  • 创建一个密钥会自动启用SSH协议,当你第一次登录启用SSH的路由器,SSH客户端会要求保存用户的密钥
  • 从IOS 12.3(4)T开始支持SSH v2(ip ssh version 2),之前只支持v1
  • 从IOS 12.1(3)T开始Cisco路由器支持SSH客户端命令,可以用来登录其他SSH服务器
  • 可以使用show ip ssh命令查看SSH服务器相关信息
21.改变IOS命令的特权等级
提问:修改特定IOS命令的特权等级
回答:
Router1(config)#privilege exec level 1 show startup-config
 
注释:
  • 缺省情况路由器支持16种特权等级,命令一般归属于0,1和15三种特权等级
  • 在特权等级0下面只支持disable, enable, exit, help, 和logout命令
    在特权等级1下面不能对配置进行修改
  • 进入特权等级15:enable,进入特权等级1:disable
  • enable(0-15)进入比当前高的特权等级
    disable(0-15)进入比当前低的特权等级
  • telnet的默认等级是特权等级1
  • 用高特权等级设定的命令,在低特权等级下便不能使用,如:
    privilege exec level 15 show ip route,则在特权0下连show命令也不能使用,除非输入:
    privilege exec level 1 show (ip)
  • Router1(config)#privilege exec reset show startup-config将命令重置到默认设置
22.基于用户的特权等级Defining Per User Privileges
提问:给不同的用户赋予不同的特权等级
回答:
Router1(config)# aaa new-model
Router1(config)# aaa authentication login default local
Router1(config)# aaa authorization exec default local
Router1(config)# username NAME privilege 10 password password
Router1(config)# privilege exec level 10 show ip route
Router1(config)# privilege exec level 1 show ip      
Router1(config)# privilege exec level 1 show  
 
注释:
  • 若给帐户指定特权等级,则当用户登录后,直接进入该特权等级,而不用输入enable
  • 通常的0,1和15三种等级弹性不足,可以定义更多的等级给不同的用户
23. 基于端口的特权等级
提问:根据登录的不同端口自动赋予特定的特权等级
回答:
Router1(config)#line aux 0
Router1(config-line)#privilege level 5
Router1(config-line)#exit
Router1(config)#privilege exec level 5 show ip route
Router1(config)#privilege exec level 1 show ip     
Router1(config)#privilege exec level 1 show  
 
注释:
  • 默认情况下,从端口登录,特权等级都是1
  • 当该端口指定特权等级后,从该端口登录,则直接进入该特权等级