Categories
Exchange

How to Authenticate to SMTP server via Command Line

Recently I had to prove to an application admin that the user he was using to send SMTP email was able to authenticate and properly send email via SMTP. The easiest way to prove that this was a configuration issue with the application and not a SMTP issue was to do it from the server via command line.

Steps to send SMTP email and authenticate:

Telnet to server on port 25

telnet servername 25

Type EHLO

EHLO
250-servername.domain.com Hello [10.149.1.55]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK

This is were it got interesting. It seems that an SMTP server asks and expects answers in Base64. For example, "VXNlcm5hbWU6" in Base64 means "Username:" and "UGFzc3dvcmQ6" means "Password:"
You can find a few Base64 encoders/decoders on the need just by googling it, I used makcoder.sourceforge.net/demo/base64.php.

So in order to authenticate to the SMTP server you will need to encode the username and password to Base64:
"Username" = "VXNlcm5hbWU="
"Password" = "UGFzc3dvcmQ="

Now to auth to the server:

Type AUTH login

AUTH login
334 VXNlcm5hbWU6

Enter the Base64 username and press enter:

VXNlcm5hbWU=

Next enter the Base64 password followed by enter

334 UGFzc3dvcmQ6
UGFzc3dvcmQ=
235 2.7.0 Authentication successful.

This shows that the user was able to authenticate and then all that’s next is to send a test email and then confirm that the mailbox recieved it

MAIL FROM: username@domain.com
250 2.1.0 username@domain.com….Sender OK
RCPT TO: username@domain.com
250 2.1.5 username@domain.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
This is a test SMTP email from application server
.
250 2.6.0 <servernameLrLySMy00000002@servername.domain.com> Queued mail for delivery

Categories
Freebsd

Passwordless ssh login with keys

Create a key with no passphrase on the source machine

[install@source ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/install/.ssh/id_rsa):
Created directory ‘/home/install/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/install/.ssh/id_rsa.
Your public key has been saved in /home/install/.ssh/id_rsa.pub.
The key fingerprint is:
66:c1:3f:95:c6:a9:d6:99:49:bf:a0:57:4f:a3:78:49 install@localhost.localdomain

Copy it to the destination machine…

[install@source ~]$ scp id_rsa.pub 10.50.2.50:~

On the destination machine create the .ssh directory and copy the id_rsa.pub to authorized_keys. If you have multiple keys you can just append it, something like this “cat id_rsa.pub >> authorized_keys”

[install@destination ~]$ mkdir .ssh
[install@destination ~]$ chmod 700 .ssh
[install@destination ~]$ cp id_rsa.pub .ssh/authorized_keys

Now you should be able to login…

[install@source .ssh]$ ssh 10.50.2.50
Last login: Fri Sep  5 14:18:01 2008 from 10.50.2.51
[install@destination ~]$

Categories
Openbsd

Creating a memory leak on Linux/Unix

I recently had to create a memory leak to do some testing, here is a snippet of code that I used to create a leak. You can adjust malloc size to allocate more memory, or adjust the usleep to adjust how aggressive it is. the code below on a machine with 500M of memory would chew up about 1% memory a second. Enjoy!

#include <stdlib.h>
#include <unistd.h>

int main(void) {
    /* An infinite loop. */
    while (1) {
       /* Try to allocate some memory. */
       malloc(8386080);
       /* sleep for a bit so its not so aggressive */
       usleep(10000);
    }
    return EXIT_SUCCESS;
}

Categories
Linux

Grant Shell access (SSH) to Root on ESX 3.5 update 2

If you’d like to allow shell access to the root account on ESX 3.5 Update 2 you need to modify the sshd_config file.

  1. Login into the console using the root account
  2. Edit the sshd_config file
     

    vi /etc/ssh/sshd_config

  3. Find "PermitRootLogin no" and change to "PermitRootLogin yes"
  4. Restart the sshd server
     

    service sshd restart

Categories
Vista

Turn off DEP on Windows Vista and NO BOOT.INI

If your used to turning DEP off completely on Windows XP you’ll have a hard time doing it on Vista.

The BOOT.INI file that is in Windows XP is now gone in Vista so you can’t just edit it to turn off DEP.

Windows Vista now comes with a command line tool called BCDEDIT.EXE that will edit the boot configs for you. It’s actually easier then editing the BOOT.INI file but only if you know the command to do it.

So here’s the command, make sure you run in with elevated priviledges.

Turn OFF DEP:
 

bcdedit.exe /set {current} nx AlwaysOff

Turn ON DEP:
 

bcdedit.exe /set {current} nx AlwaysOn

 

Categories
Openbsd

wget through proxy tutorial

Ok so I had an issue using wget from the cmd line on my linux box, so here is how to get a proxy to work with wget:

First off export a variable called "http_proxy":

export http_proxy=192.168.1.2

This will try to get to your proxy via port 80, you could also specify like this(if you are on another port):

export http_proxy=192.168.1.2:8080

Then connect specifying your auth creds if you need to pass any:

wget –proxy-user=myusername –proxy-password=mypassword http://www.myserver.com/download/strace-4.5.15-1.el5.x86_64.rpm

 

And you should be good to go!

Categories
Windows

Convert accountExpires attribute in AD to date

If you’ve ever exported the accountExpires attribute from AD you’ll notice that it’s an 64-bit number. It represents the number of 100-nanosecond intervals since 12:00 AM January 1, 1601 in UTC. What this means is that it’s practically impossible to read unless your a math genius. 😉

Here is a quick VBS script that will take that number and convert it to a real date:

Dim WshShell, oExec, objArgs, exe, work
Set WshShell = CreateObject("WScript.Shell")
Set objArgs = Wscript.Arguments
if objArgs.count = 0 Then
Wscript.Echo "FileTime argument required"
Wscript.Quit
end If
exe = "w32tm.exe /ntte " & objArgs(0)
set oExec = WshShell.Exec(exe)
Do While oExec.Status = 0
WScript.Sleep 100
Loop
work = Split(oExec.StdOut.Read(60))
Wscript.Echo work(3) & " " & work(4)

Just copy and paste this into notepad and save as finddate.vbs. Then just run "finddate.vbs <accountExpires value>"

Finddate.vbs 128674944000000000

Would result in this pop up:

date.jpg

Categories
Linux

Setting cpu affinity on linux

Here is a simple way to bind a proc to a cpu. The taskset command is part of the util-linux package.

Bind process 2225 to processor 0:

taskset -p -c 0 2225

Bind process 2225 to processor 1:

taskset -p -c 1 2225

Bind process 2225 to processor 0 and 1:

taskset -p -c 0,1 2225

You can also bind a process at execution:

taskset -c 0 sshd

Retrieving the pids current affinity:

[root@localhost ~]# taskset -p 2225
pid 2225’s current affinity mask: 3

Categories
Linux

ftp vs. ftps performance data

In a previous entry Enabling ftps on vsftpd I showed how to turn on ftps in vsftpd. I have since did a little sample to see how this would affect cpu by turning on secure transfers. The results are odd, but I ran it twice and it is correct…

The ftp get script I used was a simple curl script that did 5 transfers and slept for 2 seconds then did another 5 transfers … etc .. for 10 loops, so a total of 50 transfers. I did this because i didnt want to flood the machine. This way the machine can take a break between transfers.

Here is the script:

#!/bin/bash

date
for i in $(seq 1 10)
do
        for i in $(seq 1 5)
        do
                curl -# -u ftptest:ftptest ftp://ftphost/10M.file > file
                #curl -# -u ftptest:ftptest ftp://ftphost/10M.file > file
                #curl –ftp-ssl-reqd –insecure -# -u ftptest:ftptest ftp://ftphost/1M.file > file
                #curl –ftp-ssl-reqd –insecure -# -u ftptest:ftptest ftp://ftphost/10M.file > file
        done
        sleep 2
done
date

And here are the results:

FTP 1M File – View image

FTPS 1M File – View image

FTP 10M File – View image

FTPS 10M File – View image

Categories
Linux

Example kickstart file with lvm

I was having some trouble creating a kickstart file with lvm partitions so I finally got it working, i dont know what i did, but I think it had something to do with sizing. I set the pv to grow over the entire disk and then sliced up the lv’s.

install
url –url=http://192.163.43.101/kickstart/rhel51/x86-64/base
bootloader –location=mbr
zerombr
clearpart –all
text
firewall –disabled
firstboot –disable
reboot
selinux –disabled

key –skip
lang en_US.UTF-8
keyboard us
network –device eth0 –bootproto dhcp –onboot=on
rootpw –iscrypted $1$O9sasdfe$fdadsfdsadqW4CMdO0jk0
firewall –disabled
authconfig –enableshadow –enablemd5
timezone –utc America/Los_Angeles

part /boot –fstype ext3 –size=100
part pv.01 –size=1 –grow
volgroup rootvg01 pv.01
logvol / –fstype ext3 –name=lv01 –vgname=rootvg01 –size=1000
logvol /tmp –fstype ext3 –name=lv03 –vgname=rootvg01 –size=1000
logvol swap –fstype swap –name=lv00 –vgname=rootvg01 –size=1000
logvol /home –fstype ext3 –name=lv02 –vgname=rootvg01 –size=1000
logvol /usr –fstype ext3 –name=lv04 –vgname=rootvg01 –size=5000
logvol /var –fstype ext3 –name=lv05 –vgname=rootvg01 –size=1000

%packages
@base

%post