Thursday, June 28, 2012

GIT Reference

I am getting absolutely tired of trying to find my GIT references again after I have found them and used them and for some reason I am unable to remember certain commands with git. I am going to use this post as a central location for all of the GIT references that I find with a short description of the command/section that I found useful there.

When creating a branch here are the steps that you want to follow:
1) First we need to create the remote branch so we have a place for us to start. We can do that with the following command:
git push origin [current-branch]:refs/heads/[branch-name]
So for example let's say that I wanted to create a new branch called bill-fix but I don't want to start at the master branch, I want to start at say our new-ui branch. So then my command would look like this:
git push origin new-ui:refs/heads/bill-fix
You can see the logic of the push command, in this example.

2) Next, we need to checkout this newly created branch so we can start work on it. This is the command for that:
git checkout --track -b [branch-name] origin/[branch-name]
So, this command is also pretty self explanatory. The first [branch-name] that appears is the name that you want your local branch to be, and the second has to be the same as the remote branch created. So using the example above, my new branch was named bill-fix but lets say that I want my local branch to be bill-fixed-everything but I want it to track the remote branch of bill-fix, then my command would look like this:
git checkout --track -b bill-fix-everything origin/bill-fix



The above steps will create a remote branch and then a local branch that you can edit that will track the newly created remote branch. There is also a way that you can create a local branch that is not remote so that way only you can see that branch. For more information about that please go to this site: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
This site also provides a good explanation about how git branches work so if you are confused about that please read it there.

Saturday, June 23, 2012

One computer, multiple networks

Now, this is a problem that I have been facing for a few years now. Let me sum it up for you. I am a former network administrator for my mom's business. Being the network administrator I completely overhauled the entire network and replaced the server a few years back. With these improvements we wanted to be able to access the internet, but only from a couple of computers. So the objective was to have to client computers connect to two separate networks, one that was just for the business and another one that was connected to the internet. When all was said and done I had one computer that was working just fine and was able to connect to both networks without any difficulty, but the second one would not do this no matter what I tried. After years of having this problem I finally found this forum topic:

http://www.velocityreviews.com/forums/t297470-wireless-and-wired-network-together-on-windows-xp.html

After reading this post I remembered everything that I learned in my networking class about how computers/routers prioritize routes. I wish I had more information but this is definitely something that I need to keep in mind for future endeavors and if anybody else is having the same problem I hope that it will help you too.

Friday, April 20, 2012

SSL VPN

While working on my final project for my security lab class, I ran across this amazing tool, OpenVPN ALS or Adito. Our group decided to implement a VPN as part of security for our network. This is all fine and dandy but we don't have any enterprise tools available to us to use. I don't know really anything about how to setup a VPN, except for making one in Windows. Anyway, in my searching on Google I found this video:

http://revision3.com/hak5/sslvpndsolo

Much thanks go to hak5.org for making this very informative video. He does talk about how to setup the service in the video and I encourage you to watch it if you are interested. I do want to post some comments I have about the service myself. I installed the server on a FC14 machine and it worked exactly the same as in the video except I installed the OpenJDK package rather than sun-java. Also, when I tried to access the VPN from a linux client machine I could not get the SSL tunnel to the server on my network working. It worked fine with Windows. I'll look into this more and try and see whats going on. Bottom line if you are looking for a simple VPN setup, this will probably do what you are looking for.

Thursday, April 12, 2012

Snort IDS

As a part of my final project for my security class this semester, we are working on defending a network against attack. Later we will work on attacking other groups' networks. I have been tasked with setting up Snort as our IDS. There is many great documents available on the web about Snort but I would like to share with you my experiences.

Before I start I must provide thanks to my TA Josh, who took the time to put together the bash script that I am basing this installation off of.

There are two main ways you can download and install snort. You can either download and compile from source, or you can download and install from an rpm. In my case I am using a VM running Fedora 14 with SELinux enabled and I chose the option of downloading and install from the rpm since it takes out some of the configuration that you need to do. As a result I will not talk about configuration and compiling from source. To start off there are some packages that you need to make sure you have.

file-devel
file-libs
php-pecl-Fileinfo
python-magic
libpcap
libpcap-devel
libtermcap-devel
wget
make
cmake
gcc
gcc-c++
bison
bison-devel
openssl
openssl-devel
zlib
zlib-devel
flex
flex-devel
python-devel
swig
GeoIP-devel
sendmail

You may not need absolutely all of these packages, but this will certainly get you everything you need.
Next, we need to obtain the .rpm file for installation. You can do this through wget or go to snort.org and download from there. Either way should work fine just make sure you choose the correct version. You will also need to download the daq .rpm as well.

wget http://www.snort.org/downloads/1410 -O snort-2.9.2.1-1.F15.i386.rpm
wget http://www.snort.org/downloads/1404 -O daq-0.6.2-1.i386.rpm


These are the only two rpms you need. You need to install them using the following command on Fedora. I am sure the process is similar for apt-get or any other package manager you use:
yum -y --nogpgcheck install daq-0.6.2-1.i386.rpm
yum -y --nogpgcheck install daq-0.6.2-1.i386.rpm
yum-complete-transaction -y
yum -y --nogpgcheck install snort-2.9.2.1-1.F15.i386.rpm


When I did this the first time I tried to install daq I actually got an error, I don't know why that is if anyone would like to elaborate feel free. However, I just went ahead and tried the installation again and it worked, the error appears to be well known and accepted. Installing snort only took one iteration. At this point you have a working snort installation. All you have left to do is install the rules/signatures. Your snort installation is located at /etc/snort and the alert file is located at /var/log/alert. You must download the rules separately from the snort.org website. You must register as a user and there is a paid version and a free version. Once downloaded you can untar the file.

After untarring the file you need to copy the contents of the new folders to /etc/snort/. Command for this is:
sudo cp rules /etc/snort
sudo cp etc /etc/snort
sudo cp -R preproc_rules /etc/snort
cp -R /usr/lib/snort-2.9.2.1_dynamicengine/* /usr/local/lib/snort_dynamicengine/
cp -R /usr/lib/snort-2.9.2.1_dynamicpreprocessor/* /usr/local/lib/snort_dynamicpreprocessor/
cp so_rules/precompiled/FC-12/i386/2.9.1.2/*.so /usr/local/lib/snort_dynamicrules/ 

At this point you have installed the current snort rules/signatures and have a working version of snort. It is recommended that you create a new snort user and change the owner of /var/log/snort/ to this new user and change the owner of /var/log/snort/alert to this new user as well. Also
chmod 600
is a good setting for read, write, execute permissions on the alert file. Snort can now be started by running the command snort. It must be run as sudo and you can look at the documentation or man page to see how to specify your own .conf file or load your own signatures. Out.

RSA 2012 Keynote

I recently ran across a video of Enrique Salem's keynote at the RSA conference 2012. If you didn't go to the conference or haven't heard the speech it really is quite interesting and is worth taking 28 minutes out of your day to listen to it. Here is a link to the video: http://www.youtube.com/watch?v=pkFTrI8R8m4

For those of you that don't know Enrique Salem is the President and CEO of Symantec Corp. I thought his comparison of Digital Natives and Digital Immigrants was very accurate. Being a digital native myself I know what he means when he says that walking out of the house without being connected to the rest of the world in someway is very disturbing. My job even requires me to be constantly connected to ensure that I do not miss anything important. I think it is important for us, as security professionals, to continue to work towards a security solution that will allow digital natives the freedom they desire and at the same time provide the digital immigrants the security they know.

Symantec also recently released a new enterprise product that appears to be a solution to this very problem. It is called "O3." For the scientific types, O3 is the molecular representation of Ozone and just like Ozone O3 was designed to protect a company's cloud services. Here is the product page for more information: http://www.symantec.com/theme.jsp?themeid=O3

Unfortunately, to me it appears that there are no big improvements over any other beefed up Firewall. The only functionality it adds is allowing users to sign on to every service in one location. From that one location administrators can keep track of and control where their data is going. Tasks that can be performed at a service level basis with our current technology. I can't completely dog on this product though. The convenience that it provides can create an environment that is easier to manage and easier to secure than trying to secure each service independently.

I believe that Mr. Salem and Symantec have a great vision for where they see security moving in the future, cloud computing is certainly among us. I also believe that O3 is the first of many steps into creating a new product that will effectively secure cloud services, respect user's privacy and allow the freedom of collaboration that we so love about the internet.

Sunday, February 19, 2012

SELinux Policy Generation

This post is going to be all about creating SELinux policy. Let me start by laying down the information that I know. I know that there are two tools that we can use to create a basic framework for me to get started. The first is the Fedora SELinux Policy Generation Tool otherwise known as polgengui. The second, non-gui version, is called selpolgen. In my example I have an application, that I created, called magic8. This is basically a program that has a client and a server component. The client sends a request to the server via port 77 and the server responds with some response. Now, I am trying to confine the server daemon to only be able to read the file "response.txt" and only append to the file "magic8d.log". This all just for practice in using the policy generation tool. I will use the GUI version as a starting point. To me it appears as if there is no manpage for either of the tools discussed above. For the record I am using 64-bit Fedora 16 and I have installed the following packages via yum:
libcap-devel
libcap-ng-devel
policycoreutils-gui.x86_64
setools-devel
First, let's start out by ensuring that our SELinux is set to permissive mode. We can check this by running the command getenforce. This will tell you what mode SELinux is in either permissive or enforcing. We can toggle the mode by running sudo setenforce 0 or sudo setenforce 1. This will set SELinux to permissive or enforcing, respectively. We want to be in permissive mode so that once we compile and install our policy we can debug the policy without SELinux blocking our every move. We can start the SELinux Policy Generation tool by going to Applications -> System Tools -> SELinux Policy Generation Tool. Once the tool starts you will be asked for what kind of policy you are creating:
I am creating a policy for a User Application but you should select the option that applies to you. Select your option and then click forward. Next, you are asked for the name of your policy and then the name and location of the executable for the application. I called my policy magic8d since I am creating policy for the Magic8 daemon and the executable is called magic8d and located in /usr/local/magic8.

Click forward once you have entered your information. The next screen asks you what user_roles will transition to 'magic8d.' This is asking what type of role is going to start the application. In an SELinux targeted policy environment every user is unconfined and since this application is utilizing a privileged port we must use sudo to start the daemon. In either case we should select unconfined.
Click forward. This screen asks you what port(s) we need to bind to. This application only uses port 77 through TCP. So the only thing we need to do here is enter 77 in the TCP box. You should enter the port number(s) that your application binds to. If you aren't sure what if any port your application binds to you can leave it blank. Later during the debugging process we can add this exception to the policy.
Click forward. This screen asks you what port(s) your application connects to. Note that this is different than binding. In our case our daemon will send information to a client again via port 77 so we must also add port 77 under the TCP area.
Click forward. Next is a list of other common functions that our application could perform. This particular application writes syslog messages so we need to select that option. For this purpose we can leave all the others blank. Again if you do not know you can leave them all blank and later in the debugging process we can add the functionality to the policy.
 Click forward. The next screen is asking you which files this application manages. My application uses two files. A file called "responce.txt" and a logfile called "magic8.log." I will add both of these files to this screen but later I will need to go back and refine the policy for both of these files. I will explain in more detail later.
Click forward. Next we will be given an opportunity to add any booleans that this application uses. My application does not use any booleans so I will leave this screen blank.
Click forward. Next we are asked where we want the policy generator to put our policy files. The default should be your home folder. This is good for me so I will leave it unchanged.
Click apply. The popup box tells you the name of the four files that this policy generator has created. In my case the Policy Generator made magic8d.te, magic8d.if, magic8d.fc, and magic8d.sh. The .te file is the type enforcement file. This is the main file the defines what our application is allowed to do. The .if file is the Interface file and this defines the permissions for the interations with files and file descriptors. The .fc file is the file contexts file and contains a list of the the files that are associated with our application and what their security context will be. Lastly, the .sh file is the setup script. We will run this script to install our policy once we are done editing it.
Click ok on this popup box. The SELinux Policy Generation Tool window will remain open. You can close it if you like, we will not need it from here on out.

Now, let's first check out the .fc file. As I said before I will need to refine the default policy because of the files that my application accesses. Specifically I will need to create a policy that allows my application to read and only read the file "responce.txt" we do not need to read any other files. Further I will refine the policy to write and only write the logfile "magic8.log" and we do not need to write to any other files. By default the policy generation tool will allow read, write, execute, delete, and create access to any files we specified for it to manage. I will now describe how to refine the policy. Here is what my .fc file looks like originally:
 What I need to do here is create two types. A read type and a write type. I need to change the security contexts of the files associated with the application. I did this blelow. As you can see the security context (system_u:object_r:magic8d_w_t,s0) is given to magic8.log and this will be my write only type and the security context (system_u:object_r:magic8d_r_t,s0) is given to responce.txt and this will be my read only type.
Save and close this file. Now lets look at the .te file. Here is my original file:
 Right now we are only concerned with lines 15 and 16
...
15 type magic8d_rw_t;
16 files_type(magic8d_rw_t)
...
These lines declare the type that is associated with the files that we changed in the .fc file. We need two change these two lines and add two more.
...
15 type magic8d_w_t;
16 files_type(magic8d_w_t)
17 type magic8d_r_t;
18 files_type(magic8d_r_)
... 
We must also comment out line 31, change line 32 and add the following line:
...
31 #manage_dirs_pattern(magic8d_t, magic8d_rw_t, magic8d_rw_t)
32 manage_files_pattern(magic8d_t, magic8d_r_t, magic8d_r_t)
33 manage_files_pattern(magic8d_t, magic8d_w_t, magic8d_w_t)...
We need to make these changes because our program does not manage any directories and we changed the magic8d_rw_t type.
Close and save this file. Next open up the .if file. This is by far the most complicated file and even I am not sure what everything in this file is supposed to do. There are many changes that you need to make. The basic idea is that everytime we see the type magic8d_rw_t we need to either change it to magic8d_r_t or magic8d_w_t and then where relevant we need to add the approprite command for the other type. Here are the changes that I made:
The first instance that I found was on line 37. This is in the search rw directories section. My application doesn't really search any directories. So I shouldn't need to allow this feature. On line 37 I will change magic8d_rw_t to magic8d_r_t and also add the line magic8d_w_t just below it. I will now also comment out lines 41 and 42 because I do not need to allow permission to search these directories.
The next instance is on line 57. This is in the read rw file files section. I need to change line 57 to
...
type magic8d_r_t;
...
Then I need to  change lines 60 and 61 to:
...
60 allow $1 magic8d_r_t:file read_file_perms;
61 allow $1 magic8d_r_t:dir list_dir_perms;
...
I do not need to add the magic8d_w_t type to this section because we do not need to read those files.
The next instance occurs on line 77 in the manage rw files section. I will change line 77 and add the next line:
...
77 type magic8d_r_t;
78 type magic8d_w_t;
...
I don't need to worry about the application managing these files so I will comment out line  81.
The next instance occurs on line 97 in the create, read, write rw dirs section. I will again change line 97 and add the following line:
...
97 type magic8d_r_t;
98 type magic8d_w_t;
...
Now, since the application doesn't manage any directories (all files are in the current directory) I will I comment out line 101.
The next instance occurs on line 179 in the administrative section. I will change line 179 and add the following line:
...
179 type magic8d_r_t;
180 type magic8d_w_t;
...
Next I will change line 187 and add the following line:
...
187 admin_pattern($1, magic8d_r_t)
188 admin_pattern($1, magic8d_w_t)
...
We need to make one more addition to this file before we are finished. We need to create a rule that will allow us to write to the files that we need to write to. We can do this by mimicing the section for reading files. Here is what I added:
...
interface(`magic8d_read_rw_files',`
    gen_require(`
        type magic8d_w_t;
    ')

    allow $1 magic8d_w_t:file write_file_perms;
    allow $1 magic8d_w_t:dir list_dir_perms;
    files_search_rw($1)
')
...
We are now finished with this file. If you did it completely when you do a ctrl + f for magic8d_rw_t the only results you should find will be commented out. All of mine are so I am finished.

Our next step is to install the policy and then debug the policy. We will use the SELinux troubleshooter for debugging and if you haven't already done so ensure that your SELinux is in permissive mode by following the steps that I outlined above. In the terminal navigate to your home directory and run the following command:

sudo ./magic8d.sh

If you forget to do sudo the script will prompt you to use sudo. If your build was successful your output should look something like this:

[bill@localhost ~]$ sudo ./magic8d.sh
Building and Loading Policy
+ make -f /usr/share/selinux/devel/Makefile
Compiling targeted magic8d module
/usr/bin/checkmodule:  loading policy configuration from tmp/magic8d.tmp
/usr/bin/checkmodule:  policy configuration loaded
/usr/bin/checkmodule:  writing binary representation (version 14) to tmp/magic8d.mod
Creating targeted magic8d.pp policy package
rm tmp/magic8d.mod tmp/magic8d.mod.fc
+ /usr/sbin/semodule -i magic8d.pp
+ /sbin/restorecon -F -R -v /usr/local/magic8/magic8d
/sbin/restorecon reset /usr/local/magic8/magic8d context unconfined_u:object_r:usr_t:s0->system_u:object_r:magic8d_exec_t:s0
+ /sbin/restorecon -F -R -v /usr/local/magic8/response.txt
/sbin/restorecon reset /usr/local/magic8/response.txt context unconfined_u:object_r:usr_t:s0->system_u:object_r:magic8d_r_t:s0
+ /sbin/restorecon -F -R -v /usr/local/magic8/magic8.log
/sbin/restorecon reset /usr/local/magic8/magic8.log context unconfined_u:object_r:usr_t:s0->system_u:object_r:magic8d_w_t:s0
+ /usr/sbin/semanage port -a -t magic8d_port_t -p tcp 77
+ /usr/sbin/semanage port -a -t magic8d_port_t -p tcp 77
/usr/sbin/semanage: Port tcp/77 already defined

At this point the policy has been installed and you are ready to debug. Again with SELinux in permissive mode. Run your application and put it through the wringer. Since your policy is probably not perfect you should receive notifications from the SELinux Troubleshooter. Take a look at these alerts and see what your program tried to do that you didn't allow it to do. Since SELinux is in permissive mode the application was still allowed to proceed but it still added an alert in the audit.log file to say that it would have been denied if SELinux was set to enforcing. In FC16 if you look in the details section of the alert it will give you the reccommended way to let SELinux allow your application this function. In general you have three choices. You can choose to ignore the problem and report it as a bug to the developer of the app because their program shouldn't have that functionality, add the privlege in your SELinux policy or tell SELinux to ignore that action and do not audit that particular privilege for the application. You can check that your application started under the correct security context by running 


ps -eZ | grep magic8d

and you should recieve something like the following:

unconfined_u:unconfined_r:magic8d_t:s0-s0:c0.c1023 21549 pts/0 00:00:00 magic8d

In this case my policy was successfully installed and is working correctly. I have received no alerts so at this point I can set SELinux to enforcing and continue testing. Once I am confident in my policy then I can deploy my policy and application to a production server.

*NOTE*
It is wise to create policy in a virtual environment because while debugging you will set your SELinux policy to permissive mode. On a production server this could lead to undesirable results. I made this only as a reference and I take no responsibility for the result of your actions while following my guide.

Saturday, February 18, 2012

First post

Welcome to my technical blog. I am using this space mainly as a resource for my personal experiences. During my undergrad studies I have learned a lot and I would like to walk through what I do here so I can come back later and reference to remember how and what I did in school. Most of the things you see here, at least at first, will be labs related to networking and security. Feel free to use the information you see here however you like. I just ask that if you found something I said on here useful you tell me and tell others, give me credit where my credit is due. I will eventually begin to post things here that I experiment with on my own and I will use this blog to record that information as well. Again I hope you find the information you see here usefull and informing.