Tuesday, July 19, 2011

Ever wanted to test a SMTP mailserver manually?

Just telnet to your mailservers TCP port 25 and enter the following commands (green):

Host#telnet 172.20.20.88 25
Trying 172.20.20.88, 25 ... Open
220 mailserver.lab.local ESMTP Sendmail 8.13.8/8.13.8/Debian-2; Tue, 19 Jul 2011 21:52:12 +0200; (No UCE/UBE) logging access from: host.lab.local(OK)-host.lab.local [172.20.20.89]
EHLO host.lab.local
250-mailserver.lab.local Hello host.lab.local [172.20.20.89], pleased to meet youH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
MAIL FROM:<test@mailserver.lab.local>
250 2.1.0 <test@mailserver.lab.local>... Sender ok
RCPT TO:<andre@lab.local.de>
250 2.1.5 <andre@lab.local.de>... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
subject:Test
text, text, text, text, text, text, text, text, text, text, text, text,
text, text, text, text, text, text, text, text, text, text, text, text,
bla ...
.
This final dot (.) is crucial. Type it, and then hit enter. This finishes your mail.
250 2.0.0 a7JJwA7887a979 Message accepted for delivery
QUIT
221 2.0.0 mailserver.lab.local closing connection

[Connection to 172.20.20.88 closed by foreign host]
Host#

Thats it. If you see errors you don't know how to fix, check these links:
http://www.samlogic.net/articles/smtp-commands-reference.htm
http://email.about.com/cs/standards/a/smtp_error_code.htm
http://www.answersthatwork.com/Download_Area/ATW_Library/Networking/Network__3-SMTP_Server_Status_Codes_and_SMTP_Error_Codes.pdf 
http://www.hosteng.com/faqfiles/SMTP%20Server%20Status%20Codes%20and%20Errors.pdf 

Cisco Unity Express SMTP problem FQDN in EHLO

Ever had the problem, because of a sub-optimal DNS implementation, that your CUE doesn't want to use the FQN in EHLO? Your SMTP Server keeps sending "Helo command rejected: need fully-qualified hostname"? Then you should try to set the CUE hostname via CLI. You could set it to something like "hostname CUE.lab.local". This doesn't work via GUI!!

Packet Capture with hostname CUE:
No.     Time        Source                Destination           Protocol Length Info
     14 26.796002   172.20.20.88       172.20.20.2       SMTP     98     S: 220 labstest.lab.local ESMTP Postfix
     16 26.796002   172.20.20.2       172.20.20.88       SMTP     62     C: EHLO CUE
     18 26.800002   172.20.20.88       172.20.20.2       SMTP     227    S: 250-labstest.lab.local | 250-PIPELINING | 250-SIZE 10485760 | 250-VRFY | 250-ETRN | 250-AUTH CRAM-MD5 GSSAPI | 250-STARTTLS | 250-ENHANCEDSTATUSCODES | 250-8BITMIME | 250 DSN
     19 26.804002   172.20.20.2       172.20.20.88       SMTP     82     C: MAIL FROM:<CUE@lab.local>
     21 26.812002   172.20.20.88       172.20.20.2       SMTP     66     S: 250 2.1.0 Ok
     22 26.812002   172.20.20.2       172.20.20.88       SMTP     90     C: RCPT TO:<andre@provider.de>
     24 26.812002   172.20.20.88       172.20.20.2       SMTP     123    S: 504 5.5.2 <CUE>: Helo command rejected: need fully-qualified hostname
     25 26.812002   172.20.20.2       172.20.20.88       SMTP     58     C: RSET
     27 26.816002   172.20.20.88       172.20.20.2       SMTP     66     S: 250 2.0.0 Ok
     28 26.816002   172.20.20.2       172.20.20.88       SMTP     58     C: QUIT
     31 26.816002   172.20.20.88       172.20.20.2       SMTP     67     S: 221 2.0.0 Bye

Packet Capture with hostname CUE.lab.local:
No.     Time        Source                Destination           Protocol Length Info
    111 840.239998  172.20.20.88       172.20.20.2       SMTP     98     S: 220 labstest.lab.local ESMTP Postfix
    113 840.243998  172.20.20.2       172.20.20.88       SMTP     79     C: EHLO CUE.lab.local
    115 840.243998  172.20.20.88       172.20.20.2       SMTP     227    S: 250-labstest.lab.local | 250-PIPELINING | 250-SIZE 10485760 | 250-VRFY | 250-ETRN | 250-AUTH CRAM-MD5 GSSAPI | 250-STARTTLS | 250-ENHANCEDSTATUSCODES | 250-8BITMIME | 250 DSN
    116 840.251998  172.20.20.2       172.20.20.88       SMTP     86     C: MAIL FROM:<CUE@lab.local>
    118 840.259998  172.20.20.88       172.20.20.2       SMTP     66     S: 250 2.1.0 Ok
    119 840.259998  172.20.20.2       172.20.20.88       SMTP     90     C: RCPT TO:<andre@provider.de>
    121 840.267998  172.20.20.88       172.20.20.2       SMTP     66     S: 250 2.1.5 Ok
    122 840.267998  172.20.20.2       172.20.20.88       SMTP     58     C: DATA
    124 840.267998  172.20.20.88       172.20.20.2       SMTP     89     S: 354 End data with <CR><LF>.<CR><LF>
    125 840.287997  172.20.20.2       172.20.20.88       SMTP     1500   C: DATA fragment, 1448 bytes
    174 840.303997  172.20.20.2       172.20.20.88       SMTP     1500   C: DATA fragment, 1448 bytes
    177 840.303997  172.20.20.2       172.20.20.88       SMTP     1500   C: DATA fragment, 1448 bytes
    178 840.303997  172.20.20.2       172.20.20.88       SMTP     1500   C: DATA fragment, 1448 bytes
    179 840.303997  172.20.20.2       172.20.20.88       SMTP     1500   C: DATA fragment, 1448 bytes
    180 840.303997  172.20.20.2       172.20.20.88       IMF      440    from: Cisco Unity Express <CUE@lab.local>, subject: Message Notification,  (text/plain) (audio/x-wav)
    189 840.307997  172.20.20.88       172.20.20.2       SMTP     89     S: 250 2.0.0 Ok: queued as 93155E8CE43
    190 840.307997  172.20.20.2       172.20.20.88       SMTP     58     C: QUIT
    193 840.311997  172.20.20.88       172.20.20.2       SMTP     67     S: 221 2.0.0 Bye

Wednesday, July 13, 2011

Remote Packet Capture in Cisco IOS

Sometimes you need a network packet capture but you don't have access to the network. That's the time for Cisco's "Embedded Packet Capture"

Lets say you want to capture the traffic on you Cisco IOS routers LAN interface. You need about 2 megabyte circular buffer.

monitor capture buffer buf1 size 2048 circular
monitor capture point ip cef cap1 gigabitethernet0/0 both 
monitor capture point associate cap1 buf1


Start the capture with:
monitor capture point start cap1


And stop the capture with:
monitor capture point stop cap1

Check if everything you need is in the trace:
show monitor cap buffer buf1 dump

And copy it to a place, in this case flash, where you can access it:
monitor capture buffer buf1 export flash:capture.pcap

You might want to download it for example via SCP. There is a seperate entry in this blog regarding SCP: http://uc-b.blogspot.com/2011/07/putty-scp-file-transfer-to-cisco-ios.html

But you could also copy it directly to a bunch of remote locations:
router#monitor capture buffer buf1 export ?
  flash0:  Location to dump buffer
  flash1:  Location to dump buffer
  flash:   Location to dump buffer
  ftp:     Location to dump buffer
  http:    Location to dump buffer
  https:   Location to dump buffer
  pram:    Location to dump buffer
  rcp:     Location to dump buffer
  scp:     Location to dump buffer
  tftp:    Location to dump buffer

router#

Cisco Link to embedded Packet Capture:
http://www.cisco.com/en/US/docs/ios/netmgmt/configuration/guide/nm_packet_capture_ps6441_TSD_Products_Configuration_Guide_Chapter.html

If you want to automate it in a quite fancy way you should have a look at Cisco Embedded Automation Systems - EASy
http://www.cisco.com/en/US/prod/collateral/iosswrel/ps6537/ps6555/ps10777/ppt_EASy_Packet_Capture_c78-577851.pdf

Sunday, July 10, 2011

Access Cisco Unity Express from the internet with private addressing

Your Cisco Unity Express Voicemail system is connected to your Cisco Callmanager Express via private addressing? And you need to access it via the Internet? No VPN available?
Well, I had this task waiting for me. Not really complicated, but somebody might find it useful ....

interface GigabitEthernet0/0
 description Internet
 ip address 1.2.3.5 255.255.255.248
 ip nat outside
!
interface ISM0/0
 ip unnumbered Loopback0
 ip nat inside
 service-module ip address 172.20.20.2 255.255.255.252
 !Application: CUE Running on ISM
 service-module ip default-gateway 172.20.20.1
!
ip nat inside source list CUE_OUT interface GigabitEthernet0/0 overload
ip nat inside source static tcp 172.20.20.2 80 1.2.3.5 9999 extendable
!
ip route 0.0.0.0 0.0.0.0 1.2.3.4
ip route 172.20.20.2 255.255.255.255 ISM0/0
!This gives your CUE access to public services (SMTP, DNS, ...)
ip access-list extended CUE_OUT
 deny   ip host 172.20.20.2 host 172.20.20.1
 permit ip host 172.20.20.2 any

Now you only need to enter this URL in your browser:
http://1.2.3.4:9999/admin

If there is a firewall in between , filtering all ports except for SIP traffic & SSH), you could set up an SSH Tunnel to fix that problem. See http://uc-b.blogspot.com/2011/07/putty-scp-file-transfer-to-cisco-ios.html

Putty & SCP => File transfer to Cisco IOS through SSH Tunnel

Had the problem that I had to update an IOS Device with only SSH access available. Solution is to use SCP over a SSH Tunnel.

To do this, go to Change settings =>  Connection => SSH => Tunnels. Replace 1.2.3.4 with the IP you want to connect to. Before you define the local port, you should verify that it's unused. Doesn't need to be 22 on local side.



 Remember to press the Add button before clicking Apply. Otherwise your settings will be lost.



Next check in a DOSs box the listening TCP ports. After entering "netstat -an -p TCP" you should find an entry like "  TCP    127.0.0.1:22           0.0.0.0:0              Listening".

Now you have to prepare the router for SCP connection. The device should already be reachable via SSH.

Enter this in your router config:

aaa new-model
aaa authentication login default local
aaa authorization exec default local
username scp secret password
ip scp server enable

That's it! Now you can move files to & from your device. I prefer to use the Putty SCP client pscp.

Copy files from flash:
pscp -scp -pw password scp@127.0.0.1:flash:test.pcap "C:\Users\andre\Downloads\test.pcap"
test.pcap             | 30 kB |  30.6 kB/s | ETA: 00:00:00 | 100%

Copy files to flash:
pscp -scp -pw password "C:\Users\andre\Downloads\cme-151-4Mv1\cme-151-4Mv1\CME 8.6\CME 8.6.0 GUI\CME8.6.0GUI.tar" scp@127.0.0.1:flash:CME8.6.0GUI.tar

This works for all TCP based protocols. Makes life a lot easier ....

Cisco link for SCP:
http://www.cisco.com/en/US/docs/ios/12_2t/12_2t2/feature/guide/ftscp.html

Friday, October 24, 2008

Cisco Callmanager Express, XML Services

I've played a little bit with the integration of XML Services to the CME. The service is hosted on a Linux system with Apache as a web server.
 Works quite well ...

The necessary CME config:

telephony-service
url services http://172.20.29.88/html/ciscoxml/menu.php


My menu.php:

root@home-nas:/usr/lib/cgi-bin# cat /var/www/html/ciscoxml/menu.php
<ciscoipphonemenu>
 <title>My XML Services</title>
 <prompt>Please make your selection.</prompt>
 <menuitem>
   <name>Telefonbuch</name>
   <url>http://172.20.29.88/html/ciscoxml/Phonebook.php</url>
 </menuitem>
 <menuitem>
   <name>RSS_Feed</name>
   <url>http://172.20.29.88/cgi-bin/rss2cisco.pl</url>
 </menuitem>
 <menuitem>
   <name>Weather, News and Stocks</name>
   <url>http://phone-xml.berbee.com/menu.xml?opts=13456</url>
 </menuitem>
</ciscoipphonemenu>
root@home-nas:/usr/lib/cgi-bin#


My Phonebook.php:

root@home-nas:/usr/lib/cgi-bin# cat /var/www/html/ciscoxml/Phonebook.php
<ciscoipphonedirectory>
 <title>XML Directory</title>
 <prompt>Please Choose:</prompt>
 <directoryentry>
   <name>pepe, schnitzel</name>
   <telephone>01234</telephone>
 </directoryentry>
 <directoryentry>
   <name>pepe, schnatzel</name>
   <telephone>3453456346</telephone>
 </directoryentry>
 <directoryentry>
   <name>pepe, schnetzel</name>
   <telephone>234523</telephone>
 </directoryentry>
</ciscoipphonedirectory>
root@home-nas:/usr/lib/cgi-bin#

My rss2cisco.pl:
You get the original one from http://dontpokebadgers.com/rss2cisco/.
Thank you Joshua!!

root@home-nas:/usr/lib/cgi-bin# cat rss2cisco.pl
#!/usr/bin/perl
use strict;
#use warnings;
use CGI;
use LWP::Simple qw($ua get);
use XML::RSS;
use Cisco::IPPhone;
use vars qw($pathto @descriptions @feeds);
($#descriptions,$#feeds) = (-1,-1);
# RSS2cisco, An RSS feed to Cisco IP Phone Script version 2.0
# Copyright 2007, Joshua Cantara
# This program is licensed under the GPL: http://www.gnu.org/licenses/gpl.txt
# Newest version can always be found at: http://dontpokebadgers.com/rss2cisco/
# ************************************************************
# ATTENTION: EDIT THE FOLLOWING VARIABLES!!
# ************************************************************
# Change the following to the folder location of rss2cisco.pl on your server
# --------> DO NOT ADD A TRAILING SLASH. <--------
$pathto = 'http://172.20.23.88/cgi-bin';
# Add/Remove RSS feeds below. An example is provided.
# --------> REMOVE "http://" <--------
push(@descriptions,'Wetter');
push(@feeds,'wetter.com/wetter_rss/wetter.xml');
push(@descriptions,'BBC World News');
push(@feeds,'newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml');
push(@descriptions,'Cisco Press Promos');
push(@feeds,'www.ciscopress.com/promotions/promotion_rss.asp');
push(@descriptions,'Cisco News');
push(@feeds,'www.channelinsider.com/rss-feeds-1.xml');
push(@descriptions,'Queenstown weather');
push(@feeds,'www.rssweather.com/wx/za//queenstown/rss.php');
# --------> There is a CISCO IMPOSED MAXIMUM of 64 feeds. <--------
# ************************************************************
# ATTENTION: DON'T CHANGE ANYTHING BELOW THIS LINE!
# ************************************************************
my $query = new CGI;  if ($query->param('rssurl') eq '') { &printmenu; }
elsif ($query->param('rssurl') ne '') { &printfeed; }
else { &error; }
exit;
################################################
# PRINT A MENU OF FEEDS
################################################
sub printmenu {
my $xmlmenu = new Cisco::IPPhone;
$xmlmenu->Menu( { Title => "Your RSS Feeds", Prompt => "Choose a Feed", Text => "" });
my $i = 0;
foreach my $item (@descriptions)
 {
 $item = encode_entities($item);
 my $url = "$pathto/rss2cisco.pl?rssurl=$i";
 $url = encode_entities($url);
 $xmlmenu->AddMenuItem({ Name => $item, URL => $url});
 $i++;
 }
print $xmlmenu->Content;
}
################################################
# PRINT A SINGLE RSS FEED
################################################
sub printfeed {
# Get and parse RSS feed
my $query = new CGI;
my $feednum = $query->param('rssurl');
my $rss = new XML::RSS();
my $rssfeed = 'http://' . $feeds[$feednum];
$ua->timeout(15);
my $raw = get($rssfeed);
$rss->parse($raw);
# Read RSS news items and convert
my $body = "";
foreach my $item (@{$rss->{'items'}})
 {
 my $itemtitle = encode_entities($item->{'title'});
 my $itemdescription = $item->{'description'};
 $itemdescription = encode_entities($itemdescription);
 $body .= $itemtitle . "\n------------------------------\n" . $itemdescription . "\n\n";
 }
if (length($body) > 3600)
 {
 $body = substr($body,0,3600);
 $body .= qq|\n------------------------------\n|;
 $body .= qq|Sorry, this feed has exceeded the maximum display size and has been truncated.|;
 }
# Prepare and return final Cisco XML document
my $xmloutput = new Cisco::IPPhone;
my $title = encode_entities($descriptions[$feednum]);
$xmloutput->Text({ Title => $title, Prompt => "Viewing Feed...", Text => $body });
print $xmloutput->Content;
}
###############################################################
# PRINT ERROR MESSAGE
###############################################################
sub error {
my $xmloutput = new Cisco::IPPhone;
$xmloutput->Text({ Title => "Error", Prompt => "Please Go Back", Text => "Sorry, an error has occured." });
print $xmloutput->Content;
}
###############################################################
# ENCODE/DECODE ENTITIES
###############################################################
sub encode_entities {
my $text = shift (@_);
$text =~ s/<(.|\n)+?>//g;
$text =~ s/’/'/g;
$text =~ s/&amp;/&amp;/g;
$text =~ s/<!--</g; $text =~ s/-->/&gt;/g;
return $text;
}
root@home-nas:/usr/lib/cgi-bin#

To get this to work you should follow the instruction on the homepage of the script (http://dontpokebadgers.com/rss2cisco/).
Additionaly, to get the installation of XML::RSS working, I had to install expat-2.0.1. Download the XML parser expat at
http://sourceforge.net/projects/expat/.

Saturday, May 10, 2008

Sendmail for GMX communication

I configured the system to send the emails with the WAV attachments to an GMX email address.
Thats my sendmail.mc:

root@home-nas:~# cat /etc/mail/sendmail.mc
include(`/usr/share/sendmail/cf/m4/cf.m4')dnl
VERSIONID(`setup debian Linux')dnl
OSTYPE(`linux')dnl
dnl# DOMAIN(`debian-mta')dnl
dnl#
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`SMART_HOST',`mail.gmx.net')dnl
define(`confTO_IDENT', `0')dnl
define(`confCW_FILE', `-o /etc/mail/local-host-names')dnl
define(`confBIND_OPTS', `WorkAroundBrokenAAAA')dnl
define(`confNO_RCPT_ACTION', `add-to-undisclosed')dnl
define(`confPRIVACY_FLAGS', `authwarnings,noexpn,novrfy')dnl
define(`confLOG_LEVEL',15)dnl
FEATURE(`genericstable')dnl
FEATURE(`generics_entire_domain')dnl
FEATURE(`relay_hosts_only')dnl
FEATURE(`authinfo',`hash -o /etc/mail/auth/client-info')dnl
FEATURE(`use_cw_file')dnl
FEATURE(`access_db', `hash -T /etc/mail/access')dnl
FEATURE(`local_procmail',`',`procmail -t -Y -a $h -d $u')dnl
FEATURE(`redirect')dnl
FEATURE(`masquerade_entire_domain')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`always_add_domain',`gmx.net')dnl
EXPOSED_USER(`root')dnl
GENERICS_DOMAIN(`home-nas.lab.test')dnl
MASQUERADE_AS(`asterisk1.local')dnl
MASQUERADE_DOMAIN(`lab.test')dnl
LOCAL_DOMAIN(`localhost.localdomain')dnl
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
root@home-nas:~#


My submit.mc:

root@home-nas:~# cat /etc/mail/submit.mc
divert(-1)dnl
#-----------------------------------------------------------------------------
# $Sendmail: submit.mc,v 8.13.8 2006-09-30 07:18:48 cowboy Exp $
#
# Copyright (c) 2000-2005 Richard Nelson. All Rights Reserved.
#
# cf/debian/submit.mc. Generated from submit.mc.in by configure.
#
# submit.mc prototype config file for building Sendmail 8.13.8
#
# Note: the .in file supports 8.7.6 - 9.0.0, but the generated
# file is customized to the version noted above.
#
# This file is used to configure Sendmail for use with Debian systems.
#
# If you modify this file, you will have to regenerate /etc/mail/submit.cf
# by running this file through the m4 preprocessor via one of the following:
# * `sendmailconfig`
# * `make`
# * `m4 /etc/mail/submit.mc > /etc/mail/submit.cf`
# The first two options are preferred as they will also update other files
# that depend upon the contents of this file.
#
# The best documentation for this .mc file is:
# /usr/share/doc/sendmail-doc/cf.README.gz
#
#-----------------------------------------------------------------------------
divert(0)dnl
#
# Copyright (c) 2000-2002 Richard Nelson. All Rights Reserved.
#
# This file is used to configure Sendmail for use with Debian systems.
#
define(`_USE_ETC_MAIL_')dnl
include(`/usr/share/sendmail/cf/m4/cf.m4')dnl
VERSIONID(`$Id: submit.mc, v 8.13.8-2 2006-09-30 07:18:48 cowboy Exp $')
OSTYPE(`debian')dnl
DOMAIN(`debian-msp')dnl
dnl #
dnl #---------------------------------------------------------------------
dnl # Masquerading information, if needed, should go here
dnl # You likely will not need this, as the MTA will do it
dnl #---------------------------------------------------------------------
dnl MASQUERADE_AS()dnl
dnl FEATURE(`masquerade_envelope')dnl
dnl #
dnl #---------------------------------------------------------------------
dnl # The real reason we're here: the FEATURE(msp)
dnl #---------------------------------------------------------------------
FEATURE(`msp', `[127.0.0.1]', `MSA')dnl
dnl #
dnl #---------------------------------------------------------------------
dnl # Some minor cleanup from FEATURE(msp)
dnl #---------------------------------------------------------------------
dnl #
dnl #---------------------------------------------------------------------
root@home-nas:~#


My client-info:

root@home-nas:~# cat /etc/mail/auth/client-info
Authinfo:mail.gmx.net "U:yaya@gmx.net" "I:yaya@gmx.net" "P:xxx" "R:gmx.net" "M:CRAM-MD5"
root@home-nas:~#


My access:

root@home-nas:~# cat /etc/mail/access
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
home-nas.lab.test RELAY

root@home-nas:~#


As mentioned before, I don't claim this to be an optimized configuration, but it works. Comments welcome.