<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>BAGL</title>
 <link href="http://jefbags.github.io/" rel="self"/>
 <link href="http://jefbags.github.io"/>
 <updated>2023-12-27T18:24:00+00:00</updated>
 <id>http://jefbags.github.io</id>
 <author>
   <name>jefbags</name>
   <email></email>
 </author>

 
 <entry>
   <title>Pushing a Docker Flask App to AWS</title>
   <link href="http://jefbags.github.io/dev/2021/08/31/Pushing-a-Docker-Flask-App-to-AWS"/>
   <updated>2021-08-31T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/dev/2021/08/31/Pushing a Docker Flask App to AWS</id>
   <content type="html">&lt;p /&gt;

&lt;h1 id=&quot;docker-part-3---to-the-moonerr-i-mean-to-the-cloud&quot;&gt;Docker! Part 3 - To the Moon…err I mean to the cloud!&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image1b.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Deploying a Docker App to AWS&lt;/p&gt;

&lt;p&gt;The purpose of this post is to see how a locally created Python Flask app in a Docker container can be uploaded and served on a public cloud provider. This is useful because that’s the environment we’d ideally be hosting things because it can be secured and scaled and is relatively cheap.  I’ll be exploring AWS’ container registry Elastic Container Services (ECS), along with strategies for deployment using EC2 and Fargate.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;ecs-its-elastic--its-a-container-its-a-service&quot;&gt;ECS: It’s Elastic,  It’s a Container, It’s a Service&lt;/h2&gt;

&lt;p&gt;I am using AWS because they off some free services for people like me to test and play. I am not necessarily advocating AWS over another cloud service provided. Actually, but sticking pretty closely to the services created within the container, I am purposely avoiding the AWS services where I can. For example, AWS offers Elastic Beanstalk and Lightsail, both of which are push-button web services. I am not going to use these right now. What I want to see is how to take a container, upload it, and run whatever services it may want. I’ll mess around with Beanstalk later because I’m assuming it scales, so&lt;/p&gt;

&lt;p&gt;So, we’ll start by looking at ECS. ECS is a cloud computing service provided by Amazon Web Services (AWS) to manage containers and allow developers to run applications in the Cloud without having to configure an environment for the code to run.&lt;/p&gt;

&lt;h3 id=&quot;setting-up-aws-ecs-on-the-localhost&quot;&gt;Setting up AWS ECS on the localhost&lt;/h3&gt;

&lt;p&gt;I have already started working in AWS, so I already have a user account and access keys created. For information on how to do this in AWS, &lt;a href=&quot;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_console&quot;&gt;please see the AWS IAM UserGuide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use AWS from the command line of the local host workstation, we need to install and configure the AWS CLI.  To install it, activate the local environment and install via pip:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install awscli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then configure the AWS connection with the command &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AWS configure&lt;/code&gt; and set up following using the credentials that were created on the AWS console. This provides CLI access to the AWS environment.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image2.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;creating-an-ecs-repository&quot;&gt;Creating an ECS repository&lt;/h3&gt;

&lt;p&gt;Then, on the AWS console, go to the ECS service dashboard and create a new ECS registration. I am using all of the default settings for now, and I am naming the repository &lt;em&gt;test_flask&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And once the registry is created, it looks something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image4.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Then, AWS literally provides the commands to push the container - click on the “View Push Commands” button.  Here’s a copy-paste:&lt;/p&gt;

&lt;p&gt;Retrieve an authentication token and authenticate your Docker client to your registry.
Use the AWS CLI:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin YOUR ID.dkr.ecr.YOUR REGION.amazonaws.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**&lt;/em&gt; This comman may result in a very important message: 
&lt;img src=&quot;/images/2021-8-31/image6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As shown, the AWS password is being stored in the clear to be used by Docker to upload the container to ECR. There is a note to configure credential helper services for this - &lt;strong&gt;Need to make a note to come back to this&lt;/strong&gt;. As this is all test material, it’s not time I want to spend right now, but acknowledge that it’s stuff like this that tends to get overlooked in the name if expediency that bites back later. As a security practitioner I should know better…&lt;/p&gt;

&lt;p&gt;Build your Docker image using the following command. 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker build -t test_flask .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Need to consider how to operationalize this. So… every time we make changes to source code, we have to rebuild and repush to ECR. Also - how would this work in a multi-developer environment (another note here to spend more time on AWS permissions)?&lt;/p&gt;

&lt;p&gt;After the build completes, tag your image so you can push the image to this repository:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker tag test_flask:latest 096911673688.dkr.ecr.us-east-2.amazonaws.com/test_flask:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Presumably this is how ECR knows which uploaded image to present as the current one. This presumes that it stores previous versions?&lt;/p&gt;

&lt;p&gt;Run the following command to push this image to your newly created AWS repository:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker push 096911673688.dkr.ecr.us-east-2.amazonaws.com/test_flask:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that will take a bit because AWS is following all of the instructions in the build files. But once it’s done, it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now that we have the container uploaded to the registry, we can create a cluster to host it, and we can make an access policy for it, and then test it.&lt;/p&gt;

&lt;h3 id=&quot;creating-the-cluster---ec2&quot;&gt;Creating the Cluster - EC2&lt;/h3&gt;

&lt;p&gt;Now that we have uploaded the container, we need a place to host it and make it available online. In AWS, there are a couple of ways to do this (that I know of), using dedicate EC2 servers or using Fargate services. I understand EC2 because it’s more relatable - it’s literally a server spun up in AWS that can be interacted with the way you would expect a server to be (it has an OS, you can SSH into it etc.). Fargate is a bit more of a new animal, so will spend some more time on it below.&lt;/p&gt;

&lt;p&gt;From the AWS Container Services menu on the left, under ECS choose Clusters. Once there, select &lt;strong&gt;create cluster&lt;/strong&gt; a new cluster. We’ll choose server + networking because we’re going to request the whole shebang. I named it test, and just left everything default for now.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I am going to choose mostly defaults here, but I wanted to point out the choices. We need to pick everything - server size, ssh keys, networking subnets etc. I am highlighting this because when I did the same thing using Fargate, none of these are needed - AWS just provisions a scalable service that is much less transparent.&lt;/p&gt;

&lt;p&gt;Also - can we marvel again at the amazingness of seeing all of this create at the push of a button??
New server with clean install, application of keys, subnet create, routing in place… The flexibility, the speed and the complexity at which these environments are spun up is astounding. In the old days, this would have been a project just to get the environment up and running. Now, it’s a couple of choices on a webpage, and the click on a button.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image8.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I just had all supporting items created from scratch, except for SSH keys VPC and security group because I already have some I use for test projects and I did not want to have to make new ones of those.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image9.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;One thing I did want to point out that is kind of important: Please note below that we’re requesting a new IAM instance role be created. This controls the security permissions to the instance. More on this below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image10.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Also, I did turn on Cloudwatch for monitoring. I will look into it briefly. I feel like it’s something I should know how to do. I assume it will cost more money. That’s something else I need to look into at some point… &lt;strong&gt;How much is all of this going to cost??&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image11.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;creating-and-running-a-task&quot;&gt;Creating and running a task&lt;/h3&gt;

&lt;p&gt;Once the cluster is created, a task needs to be defined and assigned to it. The task at hand? Running our container of course. What container, you ask? The one we put into the registry, of course.&lt;/p&gt;

&lt;p&gt;From the Elastic Container Service (ECS) dashboard, choose Task Definitions.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image12.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For Launch Type, we’ll choose EC2, because remember that’s what we set up above. Under task definition, select the task you created above. It automatically fills in. In the cluster name enter the name of the cluster we created.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image13.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;opening-the-firewall&quot;&gt;Opening the Firewall&lt;/h3&gt;

&lt;p&gt;In order to access the content from outside the VPC, the port must be opened up via and ACL entry. This is controlled via the security group assigned to the EC2 container (set up above). To test the Flask service, we’ll just open the port we exposed in the container (8888) and apply it to the security group. This can be accessed from the EC2 console.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image14.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;setting-a-registry-access-policy&quot;&gt;Setting a registry access policy&lt;/h3&gt;

&lt;p&gt;The registry entry we created for the container is private, so it will need a policy to permit other services to read it. This is done in the IAM service. Just create a new policy - for service choose Elastic Container Registry, and then pick the container that was uploaded there above. Then, just choose the actions that should be permitted. I limited those here to read and list, just for testing purposes. There is a section for limiting access that could require MFA, or limit to a specific IP address or range. I could imagine doing this in production to further make things secure (e.g. limiting access to the VPC etc.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image15.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;and-finallytesting-the-url&quot;&gt;and Finally…Testing the URL&lt;/h3&gt;

&lt;p&gt;After all that, we can test that 1) the task is running in 2) the cluster we created and loaded on to the 3) EC2 server and is serving the 4) container we created and loaded on to the 5) Elastic Container Registry.&lt;/p&gt;

&lt;p&gt;From the EC2 dashboard, we can grab the public IP address this train has been assigned. And, assuming all has gone correctly….&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image16.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Success!&lt;/p&gt;

&lt;h3 id=&quot;fargate&quot;&gt;Fargate&lt;/h3&gt;

&lt;p&gt;I also messed around with doing all of the above on Amazon’s Fargate service. Basically, it’s a serverless hosting service for the cluster. Instead of provisioning a dedicated EC2 server, with an OS that is accessible/manageable, Fargate is simply an entity designed to serve exactly the task it has provisioned to serve. It scales automatically, and you get charged by the load. From a set up point of view, it was much, much easier. I didn’t go too far down this road because it’s getting a bit further into the the AWS rabbit hole, and I am legitimately trying to avoid that. However, absolutely this assuredly is the future.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This was fun because I moved off my localhost into the cloud. I’m not sure how practical it is to run a Flask server anyway in production. But for that, I guess I could use gunicorn/nginx or something. Anyway, this was a POC. It was a fun exercise. My key take-away though: I expected that the act of moving my agnotic, standalone innocent Docker container to the cloud would be more straight forward. It was NOT. There is every bit as much lingo and AWS nonsense here as doing anything in this environment. Honestly, if I wanted to serve a Flask app in AWS, I just would be simplified the whole thing and used Elastic Beanstalk or something. I guess the point I am trying to make here is that even when it’s supposed to simple, it’s not. I find that nefarious. It reminds of a tried and true meme. Adios.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-31/image17.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;links&quot;&gt;Links&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.section.io/engineering-education/using-ecs-to-deploy-docker-app-to-aws/&quot;&gt;Section.io - Using ECS to deploy Docker app to AWS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docker-curriculum.com/#docker-on-aws&quot;&gt;https://docker-curriculum.com/#docker-on-aws&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_console&quot;&gt;AWS IAM/latest/UserGuide&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://aws.amazon.com/blogs/opensource/deploying-python-flask-microservices-to-aws-using-open-source-tools/&quot;&gt;Deploying Python Flask microservices to AWS using open source tools&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</content>
 </entry>
 
 <entry>
   <title>Interacting with Docker Containers</title>
   <link href="http://jefbags.github.io/dev/2021/08/15/Interacting-with-Docker-Containers"/>
   <updated>2021-08-15T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/dev/2021/08/15/Interacting with Docker Containers</id>
   <content type="html">&lt;p /&gt;

&lt;h1 id=&quot;docker-part-2---i-see-youre-there-but-are-you-real&quot;&gt;Docker! Part 2 - I see you’re there, but are you real?&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image1.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Deeper Dive into the Container architecture&lt;/p&gt;

&lt;p&gt;The purpose of this post is to get a little deeper into interacting with Docker containers with the purpose of understanding how they are made useful development environments. We’ll look at command executions, volumes, and basic development infrastructure. Following posts will focus on more advanced topics like more complex build scripts, uploading to AWS and multi-container orchestration.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;i-cant-get-no-interaction&quot;&gt;I can’t get no… Interaction&lt;/h2&gt;

&lt;p&gt;As noted previously, I am using both Visual Studio Code and PyCharm Pro as IDE’s, and I intend to exploit the Docker plugin available for both of them to the fullest possible extent. It just makes things easier. Purists be damned.&lt;/p&gt;

&lt;p&gt;Using VS Code, I was able to get up and running pretty fast with my container. As shown below, using the default Docker plugin config in VS Code, I can get to the filesystem, and open up files for editing in the IDE.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Pycharm was a bit more complicated. I wanted to focus on figuring out how to use it because I do a lot of development in Python, and PyCharm automates a lot of the mundane stuff quite well. The setup on Pycharm was not as straight forward as VS Code. But I think a key reason for this is that &lt;em&gt;I have not been thinking about containers the right way…&lt;/em&gt; I have been thinking of them as mini virtual machines that are to be built and curated and nurtured over time. Like plants. &lt;strong&gt;But that is entirely wrong!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/plant.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Docker containers are not plants.” - Albert Einstein&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Docker container is best not managed like a plant. As a matter of fact, it’s not meant to be managed at all. &lt;strong&gt;Containers are meant to be be spun up when they are needed, and custom built based on a pre-defined script&lt;/strong&gt; that includes all of the software, files, and connectivity that is needed to make them run.  When I finally realized this, it changed the way I was approaching interacting with this technology. Instead of building a machine and developing in it, I will develop outside of it, and then just push everything to it at build time.&lt;/p&gt;

&lt;p&gt;Docker makes this easy - &lt;strong&gt;Docker Compose&lt;/strong&gt; allows for environment scripting using Dockerfiles and docker-compose scripts. I referred to several websites to learn how to do this, &lt;a href=&quot;https://blog.jetbrains.com/pycharm/2017/03/docker-compose-getting-flask-up-and-running/&quot;&gt;notably one from PyCharm&lt;/a&gt; that was a very helpful start.&lt;/p&gt;

&lt;h2 id=&quot;simple-project-1---simple-web-app&quot;&gt;Simple project #1 - Simple web app&lt;/h2&gt;

&lt;p&gt;As documented in the last post, I pulled the official nginx image from the Docker registry. Right out of the gate, I was surprised to see how light the images on the Docker registry are. I mean really, really light. You are not getting a complete, fully loaded Linux OS from liveCD. &lt;strong&gt;&lt;em&gt;There’s no ping command for God’s sake.&lt;/em&gt;&lt;/strong&gt; So, everything has to get added. Per the &lt;a href=&quot;https://docs.docker.com/develop/dev-best-practices/&quot;&gt;Docker best practices guide&lt;/a&gt;, this is intention. Even the scripts should be kept as compact as possible, more on that below. Anyway onto the scripts.&lt;/p&gt;

&lt;h3 id=&quot;the-set-up&quot;&gt;The Set Up&lt;/h3&gt;

&lt;p&gt;So, inside baseball comment for people using PyCharm - you want to create a local project on the host PC. This is so counter-intuitive to the initiated like me - but remember, we’re developing locally, and spinning up. In the old days, these things all had to be installed manually. Using CD’s. Now it’s just a line in a yml file. I’m not sure which of the meme dogs below this would refer to.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image2.jpg&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;There are three main files were going to be concerned with:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Dockerfile&lt;/strong&gt;: where we will set up the Python environment for the app - there are a bunch of cool things we can do in here. &lt;a href=&quot;https://docs.docker.com/engine/reference/builder/&quot;&gt;The Docker website has a great reference too&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;docker-compose.yml&lt;/strong&gt; to set up how to run the Dockerfile, and add the webapp, a database, expose ports, etc.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;docker-compose.dev.yml&lt;/strong&gt; to make some changes for local development. In this case, it’s where the volume is defined. Please recall that the volume is where more persistent storage is maintained. I don’t fully understand why this has to be in a separate compose folder, or even how Docker knows it’s there. I will come back to this.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also - a &lt;strong&gt;requirements.txt&lt;/strong&gt; is necessary in order to inform and install the python specific dependencies. For now, we can just add “Flask=2.0.1”, as &lt;a href=&quot;https://pypi.org/project/Flask/&quot;&gt;this was the current Flask version at the time of this post&lt;/a&gt;. Of course, it is possible to get all of the requirements for a python project by simply freezing from within the project directory:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip freeze &amp;gt; requirements.txt&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;the-dockerfile&quot;&gt;The Dockerfile&lt;/h3&gt;
&lt;p&gt;Below is the file being used for this project.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;FROM python:3

EXPOSE 5000

RUN mkdir /app
WORKDIR /app

COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

COPY . /app

CMD python app.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This isn’t too bad. Here’s how I understand it:
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FROM python:3&lt;/code&gt; means we’re pulling the pre-made python image from the Docker Hub. We’re then exposing port 5000, because that’s what Flask will run on. On the new container, we’ll make a directory for the app and work in it. 
After copying requirements.txt to the directory, we’ll install all the libraries using pip. Then we’ll copy all of the project files over. Finally, we’ll run the Flask app.py.&lt;/p&gt;

&lt;h3 id=&quot;the-docker-composeyml-file&quot;&gt;The docker-compose.yml file&lt;/h3&gt;
&lt;p&gt;Below is the file being used for this project.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;version: '3.7'
services:
  web:
    build: .
    ports:
    - &quot;5000:5000&quot;
    security_opt:
      - seccomp:unconfined
      - apparmor:unconfined
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The file is split up into service definitions. Services may include things like web, db, frontend, reddis etc. Since we are doing a simple web app, we only need web. We are building from the Dockerfile in the current directory (“.”), and binding the container and the host machine to the exposed port, 5000, the default port for the Flask web server. The last piece is me simply disabling apparmor for this container. I know it is wrong, and I will go back eventually and correct this.&lt;/p&gt;

&lt;h3 id=&quot;the-docker-composedevyml-file&quot;&gt;The docker-compose.dev.yml file&lt;/h3&gt;
&lt;p&gt;Below is the file being used for this project. A good reference is &lt;a href=&quot;https://docs.docker.com/compose/compose-file/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;version: '3.7'
services:
  web:
    volumes:
      - .:/app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I am confused by the use of a second yml config file - I think it’s to separate the volume definition from the rest of the parameters, but I need to look more into how this works. How does Docker know which compose file to look at? You can specify with the -f switch:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose -f docker-compose.dev.yml up --build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Presumably if you don’t specify, it tries to look at them all. &lt;a href=&quot;https://docs.docker.com/language/python/develop/&quot;&gt;There’s more on development uses for Python on the Docker website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Volumes are also a bit of a mystery… There is a ton of great info on this subject &lt;a href=&quot;https://docs.docker.com/storage/volumes/&quot;&gt;on the Docker website as well&lt;/a&gt;, but I am just going to highlight the key takeaways I learned from this project. Some notes directly from Docker: Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. Volumes can be more safely shared among multiple containers and volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality. New volumes can have their content pre-populated by a container. And finally, a volume does not increase the size of the containers using it, and the volume’s contents exist outside the lifecycle of a given container.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In the case of this example, we are using &lt;a href=&quot;https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference&quot;&gt;the short syntax&lt;/a&gt; to assign the relative path of the current directory (“.”) to the target container path where the volume is mounted. In this case that will be the “/app” directory where we are copying all of the application files.&lt;/p&gt;

&lt;p&gt;Note that on the first invocation of docker-compose up the volume will be created. The same volume will be reused on following invocations (e.g. using the –build switch). It’s possible to have the same volume assigned to different paths in the container. You can also use externally created volumes in compose - see the reference docs for more.&lt;/p&gt;

&lt;h3 id=&quot;pycharm---set-the-interpreter&quot;&gt;PyCharm - set the interpreter&lt;/h3&gt;

&lt;p&gt;Once the local project has been created, it is necessary to change the interpreter to and signify that it’s based on Docker Compose. The purpose of this is to allow you to run the app directly form PyCharm using Docker-compose. I know this seems decadent considering this all can be done from the terminal, but it can save time.&lt;/p&gt;

&lt;p&gt;To do that, you just need to click on the interpreter bar at the bottom right part of the screen, and select “Add a new interpreter”. Choose “Docker Compose”, with the settings below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image4.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After that, you need to map a path which will map the project root with the /app directory in the container. I am not sure why this is needed if that’s documented in the docker-compose file, but &lt;a href=&quot;https://blog.jetbrains.com/pycharm/2017/03/docker-compose-getting-flask-up-and-running/&quot;&gt;that’s what the instructions say&lt;/a&gt; and it’s not that big enough of a deal to spend a lot of time on. When the interpreter is set up, it can be used to set up a run or debug configuration, as shown below. I set up two, one for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose up&lt;/code&gt; and another one for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose up --build&lt;/code&gt;. The difference between these two is that the –build parameter will Build images before starting the containers which means that changes to the application files will be picked up and reflected in the browser.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;testing-the-web-app&quot;&gt;Testing the web app&lt;/h3&gt;

&lt;p&gt;When all the set up is done, the container can be created using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose up&lt;/code&gt; command in the terminal, or using the run configuration in PyCharm. The Deploy Log screen will show the progress of the deployment, and will show an errors that are encountered.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Once the log indicates that the webserver is “Running on http://172.18.0.2:5000/ (Press CTRL+C to quit)”, then the content should be available in the browser.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/2021-8-15/image8.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Ok, continuing to make progress! Today’s work makes using Docker for development as a viable solution. Next time, let’s try to deploy to AWS.&lt;/p&gt;

&lt;h3 id=&quot;links&quot;&gt;Links&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.jetbrains.com/pycharm/2017/03/docker-compose-getting-flask-up-and-running/&quot;&gt;https://blog.jetbrains.com/pycharm/2017/03/docker-compose-getting-flask-up-and-running/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.docker.com/engine/reference/builder/&quot;&gt;https://docs.docker.com/engine/reference/builder/)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.docker.com/compose/compose-file/&quot;&gt;https://docs.docker.com/compose/compose-file/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.docker.com/language/python/develop/&quot;&gt;https://docs.docker.com/language/python/develop/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.docker.com/storage/volumes/&quot;&gt;https://docs.docker.com/storage/volumes/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>First Docker Image</title>
   <link href="http://jefbags.github.io/dev/2021/08/02/First-Docker-Image"/>
   <updated>2021-08-02T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/dev/2021/08/02/First Docker Image</id>
   <content type="html">&lt;p /&gt;

&lt;h1 id=&quot;docker-part-1---start-it-up&quot;&gt;Docker! Part 1 - Start It Up&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/08-02-2021/docker-logo1.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s Learn How to Use Containers!&lt;/p&gt;

&lt;p&gt;The purpose of this post is to run through basics of starting and interacting with Docker containers. Following posts will focus on more advanced topics like uploading to AWS and orchestration.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;installing&quot;&gt;Installing&lt;/h2&gt;

&lt;p&gt;Not going to cover it as there are a tons of posts about it.  I am using a Debian version of Linux, and VS Code to develop, will reference that. One note on this: Docker will install in Linux requiring root privileges to run. This can create issues. I referenced the page below for managing the security requirements:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/engine/install/linux-postinstall/&quot;&gt;https://docs.docker.com/engine/install/linux-postinstall/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also - this is a practical guide. I am going to use all the cheap and easy shortcuts, IDE tricks and GUI bs I can find. Purists will say this is the cheating of the weak, but I am undeterred. The purpose of this is to document practical, usable techniques for implementing this architecture. Being efficient enables greater breadth of exploration.&lt;/p&gt;

&lt;h2 id=&quot;lay-of-the-land&quot;&gt;Lay of the Land&lt;/h2&gt;

&lt;p&gt;OK, so the problem with containers for old school people like me is that it’s all encapsulated and virtual. You can’t see a container. You can’t touch it. It’s not a piece of equipment that sits on a rack. So… how do we know what’s there??&lt;/p&gt;

&lt;h3 id=&quot;identifying-my-containers-images-and-volumes&quot;&gt;Identifying my containers, images and volumes&lt;/h3&gt;

&lt;p&gt;First, some terminology: there are different components to this, and they all specify different things.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/engine/reference/commandline/container/&quot;&gt;&lt;strong&gt;Command Line Reference&lt;/strong&gt;: https://hub.docker.com/search?type=image&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;An &lt;strong&gt;Image&lt;/strong&gt; is the source code for containers. So, they are source the OS, DB employed for a particular container instance.
&lt;strong&gt;Image Location&lt;/strong&gt;: /var/lib/docker&lt;br /&gt;
&lt;strong&gt;Image List Command&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker images&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A &lt;strong&gt;Container&lt;/strong&gt; is the implementation of an image. It’s the running ‘virtual’ machine.&lt;br /&gt;
&lt;strong&gt;Container Location&lt;/strong&gt;: /var/lib/docker&lt;br /&gt;
&lt;strong&gt;Container List Command&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker ps -a&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A &lt;strong&gt;Volume&lt;/strong&gt; is a storage unit that permits persistence between instantiations of containers. It is the place where is changes, user data are stored. They also allow for sharing of data between containers. 
&lt;strong&gt;Volume Location&lt;/strong&gt;: /var/lib/docker&lt;br /&gt;
&lt;strong&gt;Volume List Command&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker volume ls&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, so that makes sense sort of…  So how do we create a running container from an image, and then add a volume to it? Let’s see.&lt;/p&gt;

&lt;h3 id=&quot;create-a-simple-container&quot;&gt;Create a simple container&lt;/h3&gt;

&lt;p&gt;First, let’s create a simple container&lt;/p&gt;

&lt;p&gt;Right off the bat, where are the images? They are available on the Docker website, including official and verified images. There are tons of them.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://hub.docker.com/search?type=image&quot;&gt;&lt;strong&gt;Docker Hub Images:&lt;/strong&gt; https://hub.docker.com/search?type=image&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 1 - Pull an image (I pulled a generic nginx becasue I want to host a web app, and this makes it easier to set up - it’s an official version):
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker pull nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To run the image as a container, we use the command &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker run&lt;/code&gt;. BUT, we want to do some other things when we run it, so here are the switches I started off with (and probably will stick until I die).&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-it /bin/bash&lt;/code&gt; - makes the container interactive (i) in a terminal (t) with bash&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--name my_nginx_container&lt;/code&gt; - call it what you want. It makes it easier to refer to it in the cmd line.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p 8080:80&lt;/code&gt;- exposes port 80 on the container to localhost port 8080. This is how to connect to services running on the container from outside it. Want more then one port? Use the -p switch multiples times (-p 8080:80 -p 4343:443)&lt;/p&gt;

&lt;h3 id=&quot;weird-issue-with-apparmor&quot;&gt;Weird Issue with AppArmor&lt;/h3&gt;

&lt;p&gt;I could not stop my nginx container. I was geting an error message indicating that permission was denied.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/08-02-2021/image1.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I google, I Stackoverflowed, and with a magic solution I neither earned nor deserve, &lt;a href=&quot;https://stackoverflow.com/questions/47223280/docker-containers-can-not-be-stopped-or-removed-permission-denied-error&quot;&gt;I found an answer to this issue.&lt;/a&gt; Same as the poster of the question, &lt;strong&gt;I installed Docker using the SNAP package manager&lt;/strong&gt;. Apparently, this also installs an AppArmor profiles that for some reason conflicts with shutting down the Docker containers. I looked into it a little and assume that there is something in the default profile for Docker that is not set right.&lt;/p&gt;

&lt;p&gt;In the interest of expediency, I decided to look at this later, and in the meantime I will run my Docker containers with AppArmor disabled (see switch: –security-opt apparmor:unconfined). This is a temporary fix, I understand the implications of doing this in production etc.&lt;/p&gt;

&lt;p&gt;So all together the command for starting my nginx container looks something like this for me:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker run --name my_nginx -p 8080:80 -ti --security-opt apparmor:unconfined nginx bash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I also can start it in VSCode using a GUI. VSCode also lets me terminal directly into the container, and this can also be done from the command line:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker exec -t -i my_nginx /bin/bash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The VSCode interface is kind of neat for something available for free. Here’s what my interface to this container looks like:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/08-02-2021/image2.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And because I exposed port 80, and because the image as nginx already built into it, the website is available on the host machine at port 8080:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/08-02-2021/image3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Ok, so we’re off to a good start. The fundamentals of containerization are not too daunting, and the appeal is obvious. For developers who need total control over their stacks no matter where they are hosted, this must offer massive amounts of control. Now that we know how to start one, lets learn a bit more about how to interact with it, develop in it, move info on and off it etc. We know we can set one up, but how is it practically useful?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Balancing an ELK on top of a Raspberry, part one</title>
   <link href="http://jefbags.github.io/sec/2016/06/18/Balancing-an-ELK-on-top-of-a-Raspberry-part-one"/>
   <updated>2016-06-18T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/sec/2016/06/18/Balancing-an-ELK-on-top-of-a-Raspberry-:-part-one</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;adding-intrusion-detection-to-openwrt-with-raspberry-pi-and-elk&quot;&gt;Adding Intrusion Detection to OpenWRT with Raspberry Pi and ELK&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/images/post7/pic2.jpg&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The goal of this projects is to install intrusion detection monitoring and alerting on a home lab network.  The following components will be installed and configured:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set up and configure Raspbian on Raspberry Pi&lt;/li&gt;
  &lt;li&gt;Install and configure Suricata for Intrusion Detection&lt;/li&gt;
  &lt;li&gt;Utilize Elastic, Logstash and Kibana for monitoring and log management&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s Begin!&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;the-archiecture&quot;&gt;The archiecture&lt;/h2&gt;

&lt;p&gt;The purpose of this project will be to set up an intrusion detection system to monitor home traffic, and specifically traffic moving between the 3 zones previously configured in the router: internal, DMZ and external.  The primary goal will to watch out for anomalies, and specfic traffic patterns we would not like to see.&lt;/p&gt;

&lt;p&gt;I wanted to set up intrusion detection in a low cost way, but I didn’t want to do any extra processing on the OpenWRT router itself.  That’s what has made using Raspberry Pi a really great solution.  It’s small, lightweight, versatile, low-power etc.&lt;/p&gt;

&lt;p&gt;Ideally, I would have set up the Raspberry Pi inline between the external and other networks.  This would have allowed for true intrusion prevention capabilities.  To do this with a Raspberry, extra work would have been required because it only has one ethernet interface.  Either a second USB NIC adapter would have been needed, or sub-intefaces and vlan’s would have been the solution.  Out of those two, I like the second better, but I don’t have an extra managed switch at the moment, and quite frankly I was too lazy to do all this now.  I will come back to later.  For the moment, setting up the detection will be the goal.&lt;/p&gt;

&lt;h2 id=&quot;setting-up-raspberry-pi&quot;&gt;Setting up Raspberry Pi&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/images/post7/pic3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This was really a non-event.  The Raspberry Pi device was extremely easy to set up and use.  The Raspberry Pi website has a ton of information on getting started with these cool little machines.  Check it out at &lt;a href=&quot;https://www.raspberrypi.org/&quot;&gt;https://www.raspberrypi.org/&lt;/a&gt;.  The device was hardened somewhat similar as described in previous posts, and also sendmail was installed for email.&lt;/p&gt;

&lt;h2 id=&quot;installing-suricata&quot;&gt;Installing Suricata&lt;/h2&gt;
&lt;p&gt;This was really easy too!&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt-get install suricata
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So… that’s it.  Just worked.  I also renamed the default config file, as follows.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mv /etc/suricata/suricata-debian.yaml /etc/suricata/suricata.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, I edited it to define the “host-os” and “$HOME_NET” and $EXTERNAL_NET” networks as applicable to the lab environment.  That is pretty much it for that too.  A tail of /var/log/suricata/fast.log will show a variety of items coming through.&lt;/p&gt;

&lt;h3 id=&quot;checksum-errors&quot;&gt;Checksum errors&lt;/h3&gt;

&lt;p&gt;In my environment, I was getting a ton of checksum errors that were really clogging up the log.  For the purposes of testing with a relatively unclutterd logs, I decided to disable these events.  This was done by setting the value of “checksum-validation” to “no” in the /etc/suricata/suricata.yaml file.  This didn’t stop all of them, so I also commented out some of the individual events in the /etc/suricata/rules/decoder-events.rules.  To test the functionality of Suricata, I created a custom rule, and then sent specfic traffic to set it off.  This will be demonstrated as part of the Logstash configuration.&lt;/p&gt;

&lt;h2 id=&quot;setting-up-the-elk-pieces&quot;&gt;Setting up the ELK pieces&lt;/h2&gt;
&lt;p&gt;To set up Logstash, Elasticsearch and Kibana, I largely followed the tutorial that was published by a security professional named &lt;strong&gt;Travis Smith&lt;/strong&gt; who figured out the specific challenges to getting these applications to run on the Raspberry Pi architecture.  He published his work on his blog at &lt;a href=&quot;http://www.tripwire.com/state-of-security/security-data-protection/sweet-security-part-2-creating-a-defensible-raspberry-pi/&quot;&gt;on his blog&lt;/a&gt;.  The tutorial is excellent and also includes the details needed to complete the install.  I will includes the pieces that are most relevant or where I veered away from the instructions.  For example, Travis Smith use Bro IDS, but I decided to go with Suricata.&lt;/p&gt;

&lt;h3 id=&quot;installing-elasticsearch&quot;&gt;Installing Elasticsearch&lt;/h3&gt;

&lt;p&gt;This was super easy.  No real need to do anything special to accomodate the ARM.  The following is from the Sweet Security set up file:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.3.2.deb
sudo dpkg -i elasticsearch-2.3.2.deb
sudo rm elasticsearch-2.3.2.deb
sudo update-rc.d elasticsearch defaults
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Replace the .deb file with the updated version from the &lt;a href=&quot;https://www.elastic.co/products&quot;&gt;elastic.co website.&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;install-logstash&quot;&gt;Install Logstash&lt;/h3&gt;

&lt;p&gt;A little more complicated, this is definitely where I appreciated Travis Smith’s work.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo wget https://download.elastic.co/logstash/logstash/packages/debian/logstash_2.3.2-1_all.deb
sudo dpkg -i logstash_2.3.2-1_all.deb
sudo rm logstash_2.3.2-1_all.deb
cd /home/pi
sudo git clone https://github.com/jnr/jffi.git
cd jffi
sudo ant jar
sudo cp build/jni/libjffi-1.2.so /opt/logstash/vendor/jruby/lib/jni/arm-Linux
cd /opt/logstash/vendor/jruby/lib
sudo zip -g jruby-complete-1.7.11.jar jni/arm-Linux/libjffi-1.2.so
cd /home/pi
sudo rm -rf jffi/
sudo update-rc.d logstash defaults
sudo /opt/logstash/bin/plugin install logstash-filter-translate
sudo mkdir /etc/logstash/translate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I didn’t end up using the Logstash translate piece, or the Sweet Security custom scripts.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo wget https://download.elastic.co/kibana/kibana/kibana-4.5.0-linux-x86.tar.gz
sudo tar -xzf kibana-4.5.0-linux-x86.tar.gz
sudo mv kibana-4.5.0-linux-x86/ /opt/kibana/
sudo apt-get -y remove nodejs-legacy nodejs nodered		#Remove nodejs on Pi3
sudo wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
sudo mv /opt/kibana/node/bin/node /opt/kibana/node/bin/node.orig
sudo mv /opt/kibana/node/bin/npm /opt/kibana/node/bin/npm.orig
sudo ln -s /usr/local/bin/node /opt/kibana/node/bin/node
sudo ln -s /usr/local/bin/npm /opt/kibana/node/bin/npm
sudo rm node_latest_armhf.deb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then setup the INIT.D file…&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo cp SweetSecurity/init.d/kibana /etc/init.d
sudo chmod 755 /etc/init.d/kibana
sudo update-rc.d kibana defaults
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;configuring-logstash-to-work-with-suricata&quot;&gt;Configuring Logstash to work with Suricata&lt;/h3&gt;

&lt;p&gt;To input data detected by Suricata into Logstash, it is necessary to configure /etc/logstash/conf.d/logstash.conf as follows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;input {
  file { 
    path =&amp;gt; [&quot;/var/log/suricata/eve.json&quot;]
    #sincedb_path =&amp;gt; [&quot;/var/lib/logstash/&quot;]
    start_position =&amp;gt; beginning
    codec =&amp;gt;   json 
    type =&amp;gt; &quot;SuricataIDPS&quot; 
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Logstash is cool because once the input is configured you can set up specific filters and actions.  For example, one thing I was interested in is seeing SSH traffic in my internal network and then getting an email letting me know it is occurring.  To set up specific actions you like that, you would do something the following.  The alert is based on a custom Suricata rule set up to monitor SSH traffic flows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if [alert][signature_id] == 999999  {
    email {
      from =&amp;gt; &quot;root&quot;
      subject =&amp;gt; &quot;Alert::  SSH connection attempt detected&quot;
      to =&amp;gt; &quot;youremail@domain.com&quot;
      via =&amp;gt; &quot;sendmail&quot;
      body =&amp;gt; &quot;Suricata detected the following event: %{[alert][signature]}.&amp;lt;p&amp;gt;  The event was detected at %{[timestamp]}&quot;
      htmlbody =&amp;gt; &quot;&amp;lt;div align='left'&amp;gt;&amp;lt;h2&amp;gt;SSH Connection alert detected from Suricata&amp;lt;/h2&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div 	align='left'&amp;gt;&amp;lt;h3&amp;gt;Full Event&amp;lt;/h3&amp;gt;&amp;lt;u&amp;gt;Signature:&amp;lt;/u&amp;gt; %{[alert][signature]}&amp;lt;br/&amp;gt;&amp;lt;u&amp;gt;Detected at:&amp;lt;/u&amp;gt; %{[timestamp]}&amp;lt;br/&amp;gt;&amp;lt;u&amp;gt;Detected from:&amp;lt;/u&amp;gt; %{[src_ip]}&amp;lt;br/&amp;gt;&amp;lt;u&amp;gt;Target:&amp;lt;/u&amp;gt; %{[dest_ip]}&amp;lt;/div&amp;gt;&quot;
      # options =&amp;gt; { &quot;location&quot; =&amp;gt; &quot;/run/sendmail&quot; }
    }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, Sendmail is being used for the emails, and relaying again through Google’s mail service.  The setup was similar to what has been done in previous posts and was really easy.  &lt;a href=&quot;https://linuxconfig.org/configuring-gmail-as-sendmail-email-relay&quot;&gt;This post&lt;/a&gt; walks through the instructions very clearly.&lt;/p&gt;

&lt;p&gt;Once all that is done, the only other thing that is needed is to set up Suricata to run at startup.  This is done quite simply by editing /etc/default/suricata and change &lt;strong&gt;set run&lt;/strong&gt; to “yes” and fix the path to the yaml file.  Unless you’re using Suricata inline and are configuring NFQUEUE, set that to PCAP as well.&lt;/p&gt;

&lt;p&gt;Once that’s done, that really should be it for basic set up.  The only other things I notice was a minor issue with an unqualified hostname/sleeping for retry errors in Sendmail based on the way the lab hosts file was set up.  This was pretty easy fixes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some other cool websites on Logstash:&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;http://dopey.io/logstash-filter-alert.html&quot;&gt;http://dopey.io/logstash-filter-alert.html&lt;/a&gt;
&lt;a href=&quot;https://github.com/SMAPPER/Logstash-Configs/blob/master/suricata.conf&quot;&gt;https://github.com/SMAPPER/Logstash-Configs/blob/master/suricata.conf&lt;/a&gt;
&lt;a href=&quot;https://www.elastic.co/guide/en/logstash/current/config-examples.html&quot;&gt;https://www.elastic.co/guide/en/logstash/current/config-examples.html&lt;/a&gt;
&lt;a href=&quot;http://tales.itnobody.com/2013/07/using-logstash-to-log-smtp-bounces-like-a-boss.html&quot;&gt;http://tales.itnobody.com/2013/07/using-logstash-to-log-smtp-bounces-like-a-boss.html&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The Raspberry Pi is a damn cool computing device!  Set up like a dream, so no real issues in this post.  Next time, we’ll focus pushing traffic from OpenWRT and performing some basic analysis.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>MHN: Deploying a Honeypot Sensor</title>
   <link href="http://jefbags.github.io/sec/2015/09/05/MHN-_Deploying_a_Honeypot_Sensor"/>
   <updated>2015-09-05T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/sec/2015/09/05/MHN:_Deploying_a_Honeypot_Sensor</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;mhn-deploying-a-honeypot&quot;&gt;MHN: Deploying a Honeypot&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic1.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In the last post, I finished setting up the server, and installing the Modern Honey Network (MHN) server and infrastructure.  Everything seems to stable and running ok, so now it’s time to move on to deploying the sensors.  Fortunately, the MHN server makes this super easy, so let’s deploy a few and see how it goes.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h3 id=&quot;sensor-architecture&quot;&gt;Sensor architecture&lt;/h3&gt;
&lt;p&gt;As described in the last post, each sensor will be pushed onto virtual devices.  I reviewed the MNH wiki pages for recommended hardware of the sensors (&lt;a href=&quot;https://github.com/threatstream/mhn/wiki/Hardware-Recommendations&quot;&gt;https://github.com/threatstream/mhn/wiki/Hardware-Recommendations&lt;/a&gt;).  ThreatStream recommends the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;512MB-1GB RAM&lt;/li&gt;
  &lt;li&gt;dual core CPU&lt;/li&gt;
  &lt;li&gt;20GB drive. &amp;lt;– could get away with less if you rolled logs aggressively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In terms of running more than one sensor on the same sensor, I referred again to the ThreatStream wiki (&lt;a href=&quot;https://github.com/threatstream/mhn/wiki/Running-Multiple-Honeypots-on-the-same-server&quot;&gt;https://github.com/threatstream/mhn/wiki/Running-Multiple-Honeypots-on-the-same-server&lt;/a&gt;) which noted the following combos to beware of and/or avoid:&lt;/p&gt;

&lt;p&gt;The following listen on port 80, and only one should run on the same sensor, unless different ports are configured:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;conpot&lt;/li&gt;
  &lt;li&gt;glastopf&lt;/li&gt;
  &lt;li&gt;wordpot&lt;/li&gt;
  &lt;li&gt;shockpot&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following listen on windows ports 445, 139, etc.  Chose one or modify to listen on different ports:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Amun&lt;/li&gt;
  &lt;li&gt;Dionaea&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These can be run with each other and any of the others (no port conflicts):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;kippo&lt;/li&gt;
  &lt;li&gt;snort&lt;/li&gt;
  &lt;li&gt;suricata&lt;/li&gt;
  &lt;li&gt;p0f&lt;/li&gt;
  &lt;li&gt;elastichoney&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Running Snort and Suricata together is generally not necessary though.&lt;/p&gt;

&lt;p&gt;Installing the sensors will follow the general arhitecture diagramed below, from the MHN website.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic2.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;deployment-kippo&quot;&gt;Deployment: kippo&lt;/h3&gt;

&lt;p&gt;we’ll start with kippo to test ssh attacks.  And again, we’ll be following along using this excelent guide from IT and Security Stuffs.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://itandsecuritystuffs.wordpress.com/2015/02/03/honeypot-networks/&quot;&gt;https://itandsecuritystuffs.wordpress.com/2015/02/03/honeypot-networks/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the command, log into the web interface, and go to the “Deploy” page, copy the command and run it on the sensor.  That’s it!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The script took a little while to run on the sensor, but it went in fine.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic4.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A couple of things about kippo…&lt;/p&gt;

&lt;p&gt;First, it was necessary to ensure that the server was listening on port 22 for ssh.  so, in previous installations we changed the ssh port.  That won’t work with the kippo deployment and the port setting in /etc/ssh/sshd_config needs to remain at 22.&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Another thing I noticed is that for whatever reason, I didn’t get a second port on which the real ssh server was listening.  According to the documentation, the program should have gotten a second port listening for ssh on 2222 or somehting like that.  I didn’t get that, so I couldn’t make a connection remotely via ssh.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;THIS WAS RESOLVED WITH CLEAN INSTALL&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;When I did try to connect, I it through kippo.  I was able to brute force the easy password using Medusa with no issue.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In MHN, the program registered me as an attacker.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post6/pic7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;A couple of bumps in setting up kippo, but all in all feel like this is in good shape.  Next time, I’ll work on securing the MHN web app a little bit more, and also digging into kippo’s functionality a bit more.  I will also prepare the firewall for external connectivity.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>In the Land of Milk and Honeypots, part four</title>
   <link href="http://jefbags.github.io/sec/2015/08/26/In-the-land-of-milk-and-honeypots-part-four"/>
   <updated>2015-08-26T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/sec/2015/08/26/In-the-land-of-milk-and-honeypots-:-part-four</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;virtually-a-server&quot;&gt;Virtually a server…&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/images/post5/pic1.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As noted in my previous entries, I have been messing around with and documenting the creation of a honeypot server and environs, and the use of tools and techniques to analyze activity. In the last post I set up the server and did basic hardening. In this post, I will finish the set up of the virtual machines and install the Modern Honey Network (MHN) application.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h3 id=&quot;testing-open-ports&quot;&gt;Testing open ports&lt;/h3&gt;

&lt;p&gt;I ran a scan of open ports on the newly created and hardened server to make sure nothing unexpected was being exposed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nmap -v -sT localhost
sudo nmap -v -sS localhost
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;installing-virtual-machine-infrastructure-using-virtualbox&quot;&gt;Installing virtual machine infrastructure using Virtualbox.&lt;/h3&gt;
&lt;p&gt;I decided to go with Virtualbox to manage the virtual machines I will use to run the test devices.  Installing Virtualbox was really easy and seemless.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt-get install virtualbox
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I decided for the sake of ease to use the GUI front-end to manage the VM’s.  I initially had some trouble with getting the application to forward X11 through the ssh tunel using xauth.  To make it work, it was necessary to ensure the following items were set.&lt;/p&gt;

&lt;p&gt;I enabled following in server sshd_config file:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;X11UseLocalHost no
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And also had to make sure that following was uncommented in my local ssh file:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ForwardX11Trusted yes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, to run the GUI of Virtualbox, I logged in using the -X switch and ran with&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;virtualbox &amp;amp;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Settign up the guest devices was extremely simplet and intuitive.  To start a virtual machine via command the line, this command worked fine.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo VBoxManage startvm &quot;VM name&quot; --type headless
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I also scripted “startmeup” as follows to automate it a little:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;set -x  # Output executed commands
set -e  # Make script fail as soon as one command fails

read VMName
sudo VBoxManage startvm &quot;$VMName&quot; --type headless
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After creating a template installed that was hardnened, I took a snapshot of it, and then made copies of it.  The cloning was trivial and went seamlessly.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post5/pic5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;cloning made easy!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I then logged into each clone and changed references to the template device.  Among files that were edited:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;/etc/hosts&lt;/li&gt;
  &lt;li&gt;/etc/hostname&lt;/li&gt;
  &lt;li&gt;$home/.bash_profile&lt;/li&gt;
  &lt;li&gt;/etc/psad/psad.conf&lt;/li&gt;
  &lt;li&gt;/etc/postfix/main.cf&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I booted up both devices and confirmed that there were no conflicts or issues.  I then created a snapshot of the newly created clone.&lt;/p&gt;

&lt;h3 id=&quot;backups&quot;&gt;Backups&lt;/h3&gt;

&lt;p&gt;In addition to the cloning using Virtualbox, I also created backups of everything using the Dump utility:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo dump 0zf /backups/bosch.boot.backup.8.27.2015 /boot
sudo dump 0zf /backups/bosch.root.backup.8.27.2015 /
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As a final edit to the firewall, I changed ICMP rules on host to disable its response to pings.  I know that scanning on the subnet will still find it, but I want the host to be as non-rsponsive and unobtrusive as possible.  I edited /etc/ufw/rules.before as follows.  This is to block ping and other ICMP messages to the host machine.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# ok icmp codes for INPUT
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j DROP
-A ufw-before-input -p icmp --icmp-type source-quench -j DROP
-A ufw-before-input -p icmp --icmp-type time-exceeded -j DROP
-A ufw-before-input -p icmp --icmp-type parameter-problem -j DROP
-A ufw-before-input -p icmp --icmp-type echo-request -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;installing-the-modern-honey-network-mhn-infrastructure&quot;&gt;Installing the Modern Honey Network (MHN) infrastructure&lt;/h2&gt;

&lt;p&gt;Installed following this excellent guide:
&lt;a href=&quot;https://itandsecuritystuffs.wordpress.com/2015/02/03/honeypot-networks/&quot;&gt;https://itandsecuritystuffs.wordpress.com/2015/02/03/honeypot-networks/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note&lt;/em&gt;: I had issues running MHN on Ubuntu 15 due to python compiling issues.  I was getting “python setup.py egg_info” failed with error code 1”.  I tried a bunch of stuff, but felt like it was a waste of time.  Because others have documented it working ok, I ended up installing on Trusty instead, with no issue.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade

cd /opt/
sudo apt-get install git -y
sudo git clone https://github.com/threatstream/mhn.git
cd mhn/scripts/
sudo -H ./install_hpfeeds.sh
sudo -H ./install_mnemosyne.sh
sudo -H ./install_honeymap.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The scripts took a while, but ran ok. I ran a status check, and everything looked ok.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo supervisorctl status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On reboot, I went to check the status of the services, and noticed that some of them failed on restart.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post5/pic6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I ran the restart command (sudo supervisorctl restart all), and everything came up ok.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post5/pic7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;issue-with-celery-worker&quot;&gt;Issue with celery-worker&lt;/h3&gt;

&lt;p&gt;I then installed the server component with the script&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo ./install_mhnserver.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This also took a while, but went in ok.  However, on completion and status check, I noticed an issue with the celery worker service.  It was failing to start with a fatal error.  Upon reviewing the developer Threatstream’s wiki on github ( &lt;a href=&quot;https://github.com/threatstream/mhn&quot;&gt;https://github.com/threatstream/mhn&lt;/a&gt;), I ran the commands below to change ownership of the log file, and that did resolve the issue.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd /var/log/mhn/
sudo chown www-data mhn.log
sudo supervisorctl start mhn-celery-worker
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I connected to the web server and confirmed it was up and running!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post5/pic11.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This looks really cool and I hope I can get it to work…&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post5/pic12.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Well, this has been productive, and the MHN application looks great!  I can’t wait to start deploying honeypots and collecting data.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>In the Land of Milk and Honeypots, part three</title>
   <link href="http://jefbags.github.io/sec/2015/08/16/In-the-land-of-milk-and-honeypots-part-three"/>
   <updated>2015-08-16T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/sec/2015/08/16/In-the-land-of-milk-and-honeypots-:-part-three</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;lets-set-up-the-server&quot;&gt;Let’s set up the server…&lt;/h2&gt;
&lt;p&gt;&lt;img align=&quot;right&quot; src=&quot;/images/linux.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As noted in my previous entries, I have been messing around with and documenting the creation of a honeypot server and environs, and the use of tools and techniques to analyze activity. In the last post I set up the router using OpenWRT. In this post, I will outline what was done to build the machine and setting up the base of the server environment.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;cheap-chips&quot;&gt;Cheap chips&lt;/h2&gt;
&lt;p&gt;The thing that is being reenforced to me as I move through this project is the ease and accessibility of the technology and software needed to complete it. While Thomas Friedman might have proclaimed that the world is flat in his book a few years back, in no other place than information technology is this more evident and apparent. There is so much readily availble electronics, and open source software, anyone can have in their hands almost immediately the tools they need. Can you think of any other profession or hobby that is so instantaneously accessible?&lt;/p&gt;

&lt;p&gt;Case in point, for this project I needed a separate, stand-alone device to throw to the wolves. And, as previously documented, I am not interested in spending too much on this project. But I know I need something with a little power behind it, otherwise what’s the point? Toward that end, I took this old computer that was in my basement, and designated it my DMZ device:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic2.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I yanked a bunch of critical pieces out of it, and put them in a box, like so… and then I replaced them with newer, cooler faster critical pieces.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And when’s all said and done, I now have a more or less modern and beefy machine for some pretty short money.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic4.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;How many cores is that? That’s right, it’s 8 bitches! I am hoping that helps with processing on the virtual machines, along with enough RAM to make it look like I am trying to overcompensate for personal shortcomings.&lt;/p&gt;

&lt;h2 id=&quot;setting-up-the-host-server&quot;&gt;Setting up the host server&lt;/h2&gt;
&lt;p&gt;For the OS, I decided to go with Ubuntu server. I looked into Windows and a bunch of distro’s but I really like Ubuntu. It’s powerful, yet friendly. Even the error messages are pleasant and helpful.  Why yes, thank you Ubuntu I think I will install that program.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For packages and software, I kept it very simple. No GUI, no extra packages, no servers, limited services etc. Actually, during the installation, when it asked me what I wanted to install, I think I only chose the SSH server, and host visualization tools. I’ll get into configuring them a little later. I also want to harden the device, even more than the guest VM’s, because this has got to last for the ages, while I imagine that the guests will be getting reset on a fairly regular basis.&lt;/p&gt;

&lt;h3 id=&quot;ssh-keys&quot;&gt;SSH keys&lt;/h3&gt;
&lt;p&gt;As with the router, will route most of the traffic through ssh, and secure authentication via keys. I generated my keys elsewere and copied them onto the server using this nifty command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh-copy-id username@ip_address
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I also added the following to sshd.config&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic8.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I limited access via ssh on my new port with a quick rule using ufw:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo ufw allow from 172.16.21.201 to any port xxxx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;other-hardening-stuff&quot;&gt;Other Hardening Stuff&lt;/h3&gt;
&lt;p&gt;I mainly followed the instructions in this pretty good guide: ( &lt;a href=&quot;http://hardenubuntu.com/&quot;&gt;http://hardenubuntu.com/&lt;/a&gt;), however I also referred to other sources, including the SANS guide (&lt;a href=&quot;http://www.sans.org/media/score/checklists/linuxchecklist.pdf&quot;&gt;http://www.sans.org/media/score/checklists/linuxchecklist.pdf&lt;/a&gt;) and NIST checklist (&lt;a href=&quot;https://www.nsa.gov/ia/_files/os/redhat/NSA_RHEL_5_GUIDE_v4.2.pdf&quot;&gt;https://www.nsa.gov/ia/_files/os/redhat/NSA_RHEL_5_GUIDE_v4.2.pdf&lt;/a&gt;) which were both slightly less applicable but still really good to look at. Among some of things that were done:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;disabled the root account
  sudo passwd -l root&lt;/li&gt;
  &lt;li&gt;changed password policy&lt;/li&gt;
  &lt;li&gt;disabled ipv6 for now&lt;/li&gt;
  &lt;li&gt;upgraded openssl&lt;/li&gt;
  &lt;li&gt;secured shared memory&lt;/li&gt;
  &lt;li&gt;limited ssh access from the nat address of the router&lt;/li&gt;
  &lt;li&gt;changed the ssh port&lt;/li&gt;
  &lt;li&gt;secured the /tmp and /var/tmp folders&lt;/li&gt;
  &lt;li&gt;removed unneeded services&lt;/li&gt;
  &lt;li&gt;disabled access to compilers&lt;/li&gt;
  &lt;li&gt;set alerts on login attempts&lt;/li&gt;
  &lt;li&gt;installed and configured fail2ban&lt;/li&gt;
  &lt;li&gt;installed and configured PSAD Intrusion Detection&lt;/li&gt;
  &lt;li&gt;installed and configured the UFW (Uncomplicated Firewall)&lt;/li&gt;
  &lt;li&gt;set configurations to prevent IP Spoofing attacks&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;set configurations to prevent Ping Floods&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  sudo iptables -A INPUT -p icmp -m limit --limit 6/s --limit-burst 1 -j ACCEPT
  sudo iptables -A INPUT -p icmp -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some notes…&lt;/p&gt;

&lt;p&gt;To get PSAD to work the following lines are required:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT -j LOG
sudo iptables -A FORWARD -j LOG
sudo ip6tables -A INPUT -j LOG
sudo ip6tables -A FORWARD -j LOG
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;If UFW is installed then this is needed instead.&lt;/em&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo ufw logging on
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I was still having problems with the psad application though.  I was getting “[psad-status] firewall setup warning” emails that indicated “You may just need to add a default logging rule to the /sbin/iptables ‘filter’ ‘INPUT’ chain”.  The thing is I had done this, so I couldn’t figure it out.   First, the IPTables commands I entered in would get wiped out after each reboot.  To combat this and save the iptables commands, I needed to save the current IPtables config using the command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables-save &amp;gt; /pathname
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and then add the following to /etc/rc.local:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables-restore &amp;lt; /pathname
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For some reason that didn’t solve it though, and no matter what I tried, I just couldn’t seem to clear the error.  So what I ended up doing is setting the psad service to start manually:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;update-rc.d psad disable
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, I added the following to rc.local to add the lines I needed, and start the service:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT -j LOG
sudo iptables -A FORWARD -j LOG
sudo ip6tables -A INPUT -j LOG
sudo ip6tables -A FORWARD -j LOG

sudo service psad start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That seemed to fix the issued related to PSAD on Ubuntu server 15.&lt;/p&gt;

&lt;h2 id=&quot;setting-up-email&quot;&gt;Setting up email&lt;/h2&gt;
&lt;p&gt;One thing I wanted from this was email up and running so I can send alerts to myself. I know that there To set up email, I decided to go with Postfix, and leverage Google for relaying. I know that there are other options. I guess could have used dynamic DNS, and set things up with my domain registration etc… but that is way more complicated than what I want to do for the purposes of this experiment. Plus, you have to give Google credit for making this so easy and accessible. There are tons on tutorials on how to set this on the Internet (I used this one: ( &lt;a href=&quot;https://wiki.amahi.org/index.php/Gmail_As_Relay_On_Ubuntu&quot;&gt;&lt;em&gt;https://wiki.amahi.org/index.php/Gmail_As_Relay_On_Ubuntu&lt;/em&gt;&lt;/a&gt;). Also, I made an account specifically for this purposes.&lt;/p&gt;

&lt;p&gt;Although the setup went fine, I did have some issues with security worth mentioning. When I tried to send a test message, I got this message from Google:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I reviewed the logs and noted the message:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SASL authentication failed; server smtp.gmail.com... Please log in via your web browser and then try again.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The fix for this is to install an application specific password in Gmail. Its necessary to edit /etc/postfix/sasl_passwd and update it with the newly generated application specific password. The new password must be re-hashed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;postmap /etc/postfix/sasl_passwd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Also, as good practice, ensure that the files /etc/postfix/sasl_passwd and /etc/postfix/sasl_passwd.db are accessible by root only by changing the ownership and permissions appropriately (chmod 400).&lt;/p&gt;

&lt;p&gt;I also secured postfix by changing a bunch of permissions on various postfix files, and also by editing the main.cfg file.  Some items of note are below.&lt;/p&gt;

&lt;p&gt;I added the following to limit denial of service attacks:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	default_process_limit = 100
	smtpd_client_connection_count_limit = 10
	smtpd_client_connection_rate_limit = 30
	queue_minfree = 20971520
	header_size_limit = 51200
	message_size_limit = 10485760
	smtpd_recipient_limit = 100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And a bunch of others to limit mail to valid recipients only:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post4/pic7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;more-hardening-stuff&quot;&gt;More hardening stuff&lt;/h2&gt;

&lt;h3 id=&quot;iptables&quot;&gt;IPTables&lt;/h3&gt;

&lt;p&gt;The hardending guide had some really neat IPTables configurations I wanted to take down for reference.&lt;/p&gt;

&lt;p&gt;Limit Imcoming SSH Connections&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
sudo iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 5 -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Rate-limit Incoming SSH Port Connections&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -I INPUT -p tcp --dport ssh -i eth0 -m state --state NEW -m recent  --set
sudo iptables -I INPUT -p tcp --dport ssh -i eth0 -m state --state NEW -m recent  --update --seconds 15 --hitcount 3 -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Anyone who tried to portscan us is locked out for an entire day.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT   -m recent --name portscan --rcheck --seconds 86400 -j DROP
sudo iptables -A FORWARD -m recent --name portscan --rcheck --seconds 86400 -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once the day has passed, remove them from the portscan list.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT   -m recent --name portscan --remove
sudo iptables -A FORWARD -m recent --name portscan --remove
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These rules add scanners to the portscan list, and log the attempt.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT   -p tcp -m tcp --dport 139 -m recent --name portscan --set -j LOG --log-prefix &quot;Portscan:&quot;
sudo iptables -A INPUT   -p tcp -m tcp --dport 139 -m recent --name portscan --set -j DROP
 
sudo iptables -A FORWARD -p tcp -m tcp --dport 139 -m recent --name portscan --set -j LOG --log-prefix &quot;Portscan:&quot;
sudo iptables -A FORWARD -p tcp -m tcp --dport 139 -m recent --name portscan --set -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Force SYN packets check&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Drop all NULL packets&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As mentioned above, changes made manually to the IPTables config need to be saved using the command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables-save &amp;gt; /pathname
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;OK, I think  this is enough for this installment.   Honestly, this was a lot of work.  Someone should create a distro that has all of this configured right out of the gate.   I’m sure someone has, but doing all of this work has been very educational.  Next time I’m going to set up backups so I don’t have to go through this again!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Book Report:   First, Break All the Rules</title>
   <link href="http://jefbags.github.io/mgmt/2015/08/03/First_Break_all_the_Rules"/>
   <updated>2015-08-03T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/mgmt/2015/08/03/First_Break_all_the_Rules</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;what-the-worlds-greatest-managers-do-differently&quot;&gt;What the World’s Greatest Managers Do Differently!&lt;/h2&gt;
&lt;p&gt;I want to capture some notes and interesting concepts I’ve learned from reading the book “First, Break All the Rules” by Marcus Buckingham and Curt Coffman (Copyright © 1999 by the Gallup Organization).
&lt;img align=&quot;left&quot; src=&quot;/images/post3/pic1.png&quot; /&gt;
The book represents over twenty five years of research conducted by the Gallup Organization.  They interviewed millions of employees and managers in order to find out what makes the most successful manager. They asked hundreds of different questions, on every conceivable aspect of the workplace, job duties, workplace satisfaction, management style etc.  They also collected metrics and other performance data on a cross section of twelve distinct industries, analyzing scores of things such as productivity, profitability, employee retention, and customer satisfaction. 
They then took all of this survey info and data, overlayed some statistical and analytical methodology, and boiled down managerial success to twelve basic questions.  These then can be further divided into 3 basic sections of employee and team maturity.&lt;/p&gt;

&lt;p&gt;So what are the 12 magic questions on which managerial success hinges?  Here’s what they came up with…&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;the-questions&quot;&gt;The Questions&lt;/h2&gt;

&lt;p&gt;Based on the statistical analysis of the data the authors collected, patterns in the effectiveness of certain managers emerged.  Managers who were able to help facilitate positive answers to the following questions for their employees were more likely to have successful, productive and happy teams.  The questions they came up with in no particular order are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In the last six months, has someone at work talked to me about my progress?&lt;/li&gt;
  &lt;li&gt;At work, do I have the opportunity to do what I do best every day?&lt;/li&gt;
  &lt;li&gt;Does my supervisor, or someone at work, seem to care about me as a person?&lt;/li&gt;
  &lt;li&gt;This last year, have I had opportunities at work to learn and grow?&lt;/li&gt;
  &lt;li&gt;In the last seven days, have I received recognition or praise for doing good work?&lt;/li&gt;
  &lt;li&gt;Does the mission/purpose of my company make me feel my job is important?&lt;/li&gt;
  &lt;li&gt;Is there someone at work who encourages my development?&lt;/li&gt;
  &lt;li&gt;Do I have the materials and equipment I need to do my work right?&lt;/li&gt;
  &lt;li&gt;Do I have a best friend at work?&lt;/li&gt;
  &lt;li&gt;At work, do my opinions seem to count?&lt;/li&gt;
  &lt;li&gt;Do I know what is expected of me at work?&lt;/li&gt;
  &lt;li&gt;Are my co-workers committed to doing quality work?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-hierarchy&quot;&gt;The Hierarchy&lt;/h2&gt;

&lt;p&gt;Here’s the thing:  The questions are not random, and need to be addressed in an approximate order.  Actually, according to the authors, a manager can’t facilitate the successful fulfillment of the higher level questions &lt;em&gt;unless&lt;/em&gt; the lower questions have been completed.  There’s a dependency.  They break the questions up into sections, almost like a Maslowian hierarchy that looks something like the following.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post3/pic2.png&quot; alt=&quot;pic1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So what happens at each level?  According to the authors, the levels and questions are broken up in the followings basic ways.&lt;/p&gt;

&lt;h3 id=&quot;level-1---base-camp-aka-what-do-i-get&quot;&gt;Level 1 - “Base Camp”, aka What do I get?&lt;/h3&gt;

&lt;p&gt;This is the most fundamental level where employees come to understand what is expected of them, expect feedback and expect to be given the direction they need to do their work everyday.   The questions that need to be answered are:
&lt;img align=&quot;right&quot; src=&quot;/images/post3/pic3.jpg&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Do I know what is expected of me at work?&lt;/li&gt;
  &lt;li&gt;Do I have the materials and equipment I need to do my work right?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The focus in this level is on excelling as a contributor. It’s a basic level of security for an employee.&lt;/p&gt;

&lt;h3 id=&quot;level-2---camp-1-aka-what-do-i-give&quot;&gt;Level 2 - “Camp 1“, aka What do I give?&lt;/h3&gt;
&lt;p&gt;The ascension to Camp 1 is a shift in maturity from inward to outward along with a desire to develop independently, contribute more pro-actively and optimize performance.  Questions include:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;At work, do I have the opportunity to do what I do best every day?&lt;/li&gt;
  &lt;li&gt;In the last seven days, have I received recognition or praise for doing good work?&lt;/li&gt;
  &lt;li&gt;Does my supervisor, or someone at work, seem to care about me as a person?&lt;/li&gt;
  &lt;li&gt;Is there someone at work who encourages my development?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here, the focus is on leadership, and professional mastery.  The employee has the opportunity to not only do his job, but create new opportunities and ways of doing things for herself and the group.&lt;/p&gt;

&lt;h3 id=&quot;level-3---camp-2-aka-do-i-belong-here&quot;&gt;Level 3 - “Camp 2“, aka Do I belong here?&lt;/h3&gt;
&lt;p&gt;At Camp 2, the focus shifts from day-to-day performance of the individual and towards the intercation of the team and group integration.  The questions below get at how well in-tune the players are with each other, and with the direction and mission of the organization:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;At work, do my opinions seem to count?&lt;/li&gt;
  &lt;li&gt;Does the mission/purpose of my company make me feel my job is important?&lt;/li&gt;
  &lt;li&gt;Are my co-workers committed to doing quality work?&lt;/li&gt;
  &lt;li&gt;Do I have a best friend at work?&lt;/li&gt;
  &lt;li&gt;In the last six months, has someone at work talked to me about my progress?&lt;/li&gt;
  &lt;li&gt;This last year, have I had opportunities at work to learn and grow?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Or basically, is the group a team, and is everyone in sync with each other and where things are going?&lt;/p&gt;

&lt;h3 id=&quot;the-summit&quot;&gt;The Summit&lt;/h3&gt;
&lt;p&gt;If a manager can help provide answers to all of these questions, then it’s possible to reach what the authors call the summit.  An excerpt from the book defines what that means exactly:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you can answer positively to all of these twelve questions, then you have reached the summit. Your focus is clear.You feel a recurring sense of achievement, as though the best of you is being called upon and the best  of you responds every single day. You look around and see others who also seem to thrill to the challenge of their work. Buoyed by your mutual understanding and your shared purpose, you climbers look out and forward to the challenges marching over the horizon. It is not easy to remain at the summit for long, with the ground shifting beneath your feet and the strong winds buffeting you this way and that. But while you are there, it is quite a feeling.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;It’s easy to think there’s a silver bullet to figuring out how to get the best from ourselves and our teams.  Do I think that these questions reflect some amount of truth?  Sure, absolutely.  But I think the devil is in the details.  I also think it’s possible to answer many of these questions affirmatively in some degree or another, and think everything is fine.  Subjectivity could easily get in the way of being honest and focussing on the rights things.&lt;/p&gt;

&lt;p&gt;I found this to be a great book and one I recommended for managers and staff alike.  In addition to the questions above, There are two things that will stay with me.&lt;/p&gt;

&lt;p&gt;First, the authors indicate many times over in the book that it is an employee’s direct manager that has the single greatest impact over the success of the individual and the team.  It is important to keep this in mind as we develop our teams and move our organizations forward.  More than perks, benefits, and even salary to some degree, the highest levels of performance come from those who are most enagaged with their teams and their mission.&lt;/p&gt;

&lt;p&gt;Second, the authors got out of their way to point out that most companies tend to focus on the top level, without adequately satisfying the lower levels.   I think the a quote from the book expresses it best.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Inexperienced climbers might suggest that if you have lots of money and not much time, you could helicopter into Camp 3 and race to the summit. Experienced guides know that you would never make it. Mountain sickness would sap your energy and slow your progress to a crawl. These guides will tell you that to reach the summit you have to pay your dues. During your ascent you have to spend a great deal of time between Base Camp and Camp 1. The more time you spend at these lower reaches, the more stamina you will have in the thin air near the summit.
&lt;img align=&quot;left&quot; src=&quot;/images/post3/pic4.png&quot; /&gt;&lt;br /&gt;
It almost sounds obvious. But over the last fifteen years most managers have been encouraged to focus much higher up the mountain. Mission statements, diversity training, self-directed work teams—all try to help employees feel they belong (Camp 2). Total quality management, re-engineering, continuous improvement, learning organizations — all address the need for employees to innovate, to challenge cozy assumptions and rebuild them a fresh, every day (Camp 3). All of these initiatives were very well conceived. Many of them were well executed. But almost all of them have withered.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As with so many other aspects of life, fundamentals are key.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>In the Land of Milk and Honeypots, part two</title>
   <link href="http://jefbags.github.io/sec/2015/07/26/In-the-land-of-milk-and-honeypots-part-two"/>
   <updated>2015-07-26T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/sec/2015/07/26/In-the-land-of-milk-and-honeypots-:-part-two</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;hardening-the-openwrt-device&quot;&gt;Hardening the OpenWRT device…&lt;/h2&gt;

&lt;p&gt;As noted in my previous entry, the purpose of this series of posts is to document the creation of a honeypot, and the use of tools and techniques to analyze activity.  In this post, I will continue configuring the OpenWRT router, lock down some of the settings, and also set up some NAT’s and open ports.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;installing-tcpdump&quot;&gt;Installing tcpdump&lt;/h2&gt;

&lt;p&gt;First things first, we have to lock down the LinkSys router.  Before we begin, there’s something I want to add to the router.  It’s one of the best, simple networking tools in the world:  tcpdump.  I want this because I am going to use it to test the natted IP’s that are created later on.&lt;/p&gt;

&lt;p&gt;To get started, first go to update the package list on the device:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;opkg update
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then install the package&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;opkg install tcpdump
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, so that was slow.  This router is struggling.  Will probably look into upgrading later on.  There is barely enough memory or space on this thing to do a lot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/Pic1.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To test that the tool is installed ok, I’ll monitor the LAN interface for ICMP traffic, and ping it:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tcpdump -i br-lan icmp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, seems to be up and running!  Rebooted a few times, and retested.  There were a couple of hiccups, and the wrong dump will easily overwhelm the device.  But generally, we are set to move on.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/Pic2.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;setting-up-public-key-authentication&quot;&gt;Setting up public key authentication&lt;/h2&gt;

&lt;p&gt;Next I need to start and lock the router down.  There are several standard steps that will be taken.  Mostly, I following along with the items noted on the OpenWRT website where an excellent tutorial exists (&lt;a href=&quot;http://wiki.openwrt.org/doc/howto/secure.access&quot;&gt;http://wiki.openwrt.org/doc/howto/secure.access&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;I want to start by setting up keys that need to be present in order to SSH to the router.  I generated a key pair on my laptop using OpenSSH, and copied the public one onto the router.  I then successfully configured the router to utilize the keys in place of the id and password.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/pic3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I also tested from my Windows machine using Putty.  To do this, it was necessary to use the PuTTYgen tool.  I imported my exiting SSH key into this tool, and then saved it as a .PPK file.  I also am using the Pageant program to save the passphrase so I don’t have to enter it everytime I log into the router.  I then disabled password auth for login:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@OpenWrt:~# uci set dropbear.@dropbear[0].PasswordAuth=off
root@OpenWrt:~# uci commit dropbear
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I then tested this by removing the private key from the putty connection and seeing what happens….&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/pic4.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;…and the connection timed out.  That is good.  I then reenabled the .PPK profile and was back in business.&lt;/p&gt;

&lt;p&gt;I also took the last piece of advice from the tutorial, and completely disabled telnet:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rm /etc/init.d/telnet
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, I changed the port that SSH listens on to something completely random and also bound it to the LAN interface only.&lt;/p&gt;

&lt;h2 id=&quot;account-management&quot;&gt;Account Management&lt;/h2&gt;

&lt;p&gt;I created a second account on the device and created a directory for it.  I also permitted it to sudo with the root password by uncommenting the following lines in visudo:&lt;/p&gt;

  	Defaults targetpw  # Ask for the password of the target user               &lt;br /&gt;
  	ALL ALL=(ALL) ALL  # WARNING: only use this together with ‘Defaults targetpw’

&lt;p&gt;I could not login with my new user account because the key was not present in the new account’s home directory.  It was necessary to copy it over (had to create the dir. too):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cp /etc/dropbear/authorized_keys /home/jefbags/.ssh/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, I tried to limit access to the web interface from http and only allow https.  However I ran out of space on the disk, so that didn’t work.  I’ll revisit that one at some point and do something, maybe tunneling via SSH.  If I were to do this though, I would bind the webserver to the LAN interface only, and pick a completely random port, as follows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;uci delete uhttpd.main.listen_http	
uci set uhttpd.main.listen_https=192.168.1.1:5551
uci commit
/etc/init.d/uhttpd restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;setting-up-the-source-nat-from-the-lan-to-the-dmz&quot;&gt;Setting up the Source NAT from the LAN to the DMZ&lt;/h2&gt;

&lt;p&gt;Now I want to ensure that when any traffic goes from the LAN to the DMZ, it gets natted to an address on the DMZ network.  We don’t have to worry about configuring an access rule for this, because noted in the last post, we are allowing all traffic from the LAN to the DMZ.&lt;/p&gt;

&lt;p&gt;To set up the natting, we need to configure a redirect on the router.  I tried by editing /etc/config/firewall directly.  Had some issues, here’s what I settled and got to work fine:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config 'redirect'
option '_name' 'Source NAT from LAN to DMZ'
option 'src' 'lan'
option 'proto' 'tcpudp'
option 'dest_ip' '172.16.21.0/24'
option 'target' 'SNAT'
option 'dest' 'dmz'
option 'src_dip' '172.16.21.201'
option 'src_ip' '192.168.1.0/24'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I also ended up creating a second rule similar to this specifically for ICMP.  At this time, I don’t know how to include both TCP-UDP and ICMP in the same rule and have it actually work.  I’m sure there’s syntax that eludes me, but this will work for now.  This is what they end up looking like in the web GUI.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/pic5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I also had issues with ARP.  Because of the source natting, the natted IP address (in this case 172.16.21.201) does not have an associated layer 2 address.  Therefore, the receiving computer will not know what MAC address to send the packets back to.  To fix this, it is necessary to associate the natted IP with the router’s MAC address.  This can be done with the IP address command, as follows below (In order to use this command, you will need to install the “IP” package.  To make it permanent and survive a reboot, the address needs to be added to /etc/config/network):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ip address add 172.16.21.201 dev eth0.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;OK, so how do I know this is working?  I can use tcpdump, which I installed earlier.  I can ping the test device I have out on the DMZ.  If I look at the LAN interface, I can see the address of my laptop, 192.168.1.13:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/pic6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;But, if I look on the DMZ interface, I can confirm that the source IP address has changed to the intended new source of 172.16.21.201l.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post2/pic7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;opening-up-dnat-on-the-dmz-to-the-wan&quot;&gt;Opening up DNAT on the DMZ to the WAN&lt;/h2&gt;

&lt;p&gt;Eventually, we’ll want to open up ports on the DMZ to the internet.  Once that happens, any services we have runnnig on the open ports will be exposed.  That’s fine though, it’s the reason this is all being set up!&lt;/p&gt;

&lt;p&gt;To configure the open ports, I will do something like the below configurations:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config redirect
    option src       wan
    option src_dport 80
    option proto     tcp
    option dest      dmz
    option dest_ip   172.16.21.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;172.16.21.2 will be the static address of the server once it gets set up.  For now, we’ll leave this redirect rule commented out in the configuration.  I will also need an access rule that permits the traffic, but I think I will come back to it as we get the server hardened and get into the testing.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Well, I do feel more secure now.  This has been a lot of stuff.  Next time, I’ll test and see how things work and then move on and setting up the server.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>In the Land of Milk and Honeypots, part one</title>
   <link href="http://jefbags.github.io/sec/2015/07/19/In-the-land-of-milk-and-honeypots-part-one"/>
   <updated>2015-07-19T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/sec/2015/07/19/In-the-land-of-milk-and-honeypots-:-part-one</id>
   <content type="html">&lt;p /&gt;

&lt;h2 id=&quot;setting-the-stage&quot;&gt;Setting the stage…&lt;/h2&gt;

&lt;p&gt;Ok, hello.  The purpose of this article is document the creation of a honeypot on my home network safely, and show some of the traffic and activities that are captured and analyzed.  It might go without saying that this is a potentially dangerous thing to do, and may jeopardize my other personal devices, and also get me in trouble with my ISP.  That being understood, safety is the most important concern in this exercise.  Where applicable, active monitoring, logging and alerting will be used to ensure manage any issues.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;why&quot;&gt;Why?&lt;/h2&gt;

&lt;p&gt;Given the danger, why do this?  Because honeypots are a great way to learn about malicious activity, how to capture and analyze it, and how to protect against it.  As a security professional, this is why we do what we do.  This is the most hands-on, direct way of understanding the technology and the risks involved.  It is also a great reason to experiment with a variety of InfoSec techniques, tools and practices.&lt;/p&gt;

&lt;h2 id=&quot;lets-begin&quot;&gt;Let’s Begin…&lt;/h2&gt;

&lt;p&gt;Ok, step 1 this process:  segment, segment, segment.    It is imperative that the traffic from the honeypot network be separate from the home network.  As stated above, I cannot put my home network at risk at all, and because of this I need to make sure the setup is entirely separate.  As part of researching this project, I read articles about others building a VM on their laptops and sticking them on the “DMZ” setting of their home router.  I am not comfortable with this setup because I assuming that the honeypot device will become completely compromised.  Once this happens, that device can be used to pivot into any other devices that can be connected to.  Therefore, proper network segmentation is the first and most important step.&lt;/p&gt;

&lt;p&gt;The right way to do this is to get a proper professional grade firewall and build out separate networks.  However, at this time, I cannot spend the money to get the kind of device that ideally is needed.  Instead, I will attempt this on a repurposed Linksys router, using the OpenWRT firmware.  I will leverage OpenWRT’s functionality to create segmentation at both layers 2 and 3 and I will use data analysis to demonstrate proper segmentation and control of traffic between the networks created.  While this is a bit of a challenge, I feel that this will be the most rewarding means of completing this project and the most learning along the way.  Also, there are other, newer firmware’s out there, notably Tomato.  Many have commented that Tomato’s interface is quite streamlined, and there are several excellent bandwidth monitoring features.  For this experiment, I decided to go with OpenWRT because of its more robust history, documentation and stability.&lt;/p&gt;

&lt;h2 id=&quot;setting-up-openwrt&quot;&gt;Setting up OpenWRT&lt;/h2&gt;

&lt;p&gt;OpenWRT is a Linux based firmware that runs on a variety of home based, inexpensive routers.  The reason I am using it is because I can utilize a relatively cheap piece of hardware, but still get a lot of the functionality I need to get what I want.  I am also going to use it to enhance other aspects of my home internet use by using other features OpenWRT has to offer.  More information can be found at the OpenWRT website (&lt;a href=&quot;http://wiki.openwrt.org&quot;&gt;&lt;em&gt;http://wiki.openwrt.org&lt;/em&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;My existing home router does not support OpenWRT.  To find on the does, I went to Ebay.  There were many of them available.  I chose a Linksys WRT54G v3 and was able to pick it up for $4.99.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic1.png&quot; alt=&quot;pic1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This is picture from Ebay.  This is literally how it looked in the box too – they didn’t even unplug the power adapter when they shipped it!  I do appreciate the quality bath towel they laid it out on though.&lt;/p&gt;

&lt;p&gt;To flash the device with OpenWRT, I followed the instructions posted on the OpenWRT website ( &lt;a href=&quot;http://wiki.openwrt.org/toh/linksys/wrt54g&quot;&gt;&lt;em&gt;http://wiki.openwrt.org/toh/linksys/wrt54g&lt;/em&gt;&lt;/a&gt;).  These instructions correspond to my specific device, other devices should use the appropriate corresponding instructions.&lt;/p&gt;

&lt;p&gt;The installation went ok, I learned the following things along the way:&lt;/p&gt;

&lt;p&gt;It was necessary to be really careful when choosing the version of OpenWRT to download and install.  As noted on the website, “with the release of ‘Attitude Adjustment (12.09 final)’ on 25th April 2013, lower end devices with only 16 MBB RAM will easily run out of memory. Recommended image for bcm47xx based devices is Backfire with brcm-2.4.”  Since this is a really old router, I am limited to Backfire version 10.03.  I am also taking the risk and installing the “brcm47xx” version because I am interested in the more full-featured version of Linux.&lt;/p&gt;

&lt;p&gt;I reset the device back to factory defaults using both the button on the back of the device, and also the setting within the webgui.  I am paranoid and OCD – who knows where this thing has been??&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic2.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The firmware upgrade seemed to go ok, and I made a telnet session ok.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic3.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I was pretty impressed by OpenWRT CLI options.  It is a pretty advanced for something running on such a small, cheap device.  Many of the options and features are those I would have expected to see on a more advanced switch or firewall.&lt;/p&gt;

&lt;p&gt;I started by taking the OpenWRT tutorial’s advice and make the device open to tftp in the event I brick it.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nvram set boot_wait=on

nvram set boot_time=10

nvram set wait_time=10

nvram commit &amp;amp;&amp;amp; reboot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once done, I proceeded to work on upgrading to the brcm47xx version of backfire 10.03.1.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic4.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Held my breath a little… the Luci web interface runs really slow.  You get the feeling this little device isn’t totally designed to use all this software,&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic5.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Success!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic6.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;designing-the-network&quot;&gt;Designing the network&lt;/h2&gt;

&lt;p&gt;To setup the device, I envisioned the following, very simple network.  The purpose of the network is to isolate my DMZ, permitting only a very specific number of port and protocols between it and the internet, and the internal network.  The goal is to create the very basic network illustrated below and ensure that traffic is being appropriately isolated.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic7.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The only traffic between the DMZ and the internal network will be syslog from the DMZ into the internal network.  This will be to analyze data from the DMZ device.  RDP and SSH originating in the internal network is desirable in order to control the DMZ device(s) from my personal PC.  Finally, devices in the DMZ will have HTTP, HTTPS, and SMTP will be opened up to the internet.  Other ports may be opened up later as part of testing.&lt;/p&gt;

&lt;h2 id=&quot;configuring-the-vlans-and-segregating-access&quot;&gt;Configuring the VLAN’s and segregating access&lt;/h2&gt;

&lt;p&gt;To set up the vlans and the firewall to control traffic at layer 3, I referred to an article on the OpenWRT website on setting up DMZ’s ( &lt;a href=&quot;http://wiki.openwrt.org/doc/howto/dmz?s%5b%5d=dmz&quot;&gt;&lt;em&gt;http://wiki.openwrt.org/doc/howto/dmz?s[]=dmz&lt;/em&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;First, I had to set up the ports, and assign the DMZ port.  On the &lt;em&gt;WRT54G router, the ports are configured on the following manner:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic8.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I set up an additional VLAN 2 on port 1 by adding the following to /etc/config/network.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config switch_vlan eth0_2

    option device   &quot;eth0&quot;

    option vlan     2

    option ports    &quot;1 5&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;*Please note that port 1 pertains to switch port 1 on the actual router.  It was also necessary to enable switch port 5, which pertains to the internal CPU of the device.  If this port is not enabled, the router cannot route the packets (learned from experience!).&lt;/p&gt;

&lt;p&gt;I then set up DMZ network:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config 'interface' dmz

    option 'ifname' eth0.2 # This corresponds to &quot;vlan2&quot; above

    option 'proto'   static

    option 'ipaddr'  172.16.21.1   #this is a separate network

    option 'netmask' 255.255.255.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I then added the following rules to the firewall by configuring /etc/config/firewall.  I decided not to enable DHCP on the DMZ network.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config 'zone'

   option 'name' 'dmz'

   option 'input' 'REJECT' # By default, stop anything coming from the DMZ

   option 'output' 'ACCEPT'

   option 'forward' 'REJECT'

   option 'network' 'dmz'

# Allow the DMZ to use the router as a DNS server

config 'rule'

   option 'src' 'dmz'

   option 'proto' 'tcpudp'

   option 'dest_port' '53'

   option 'target' 'ACCEPT'

# Allow the DMZ to use the router as a DHCP server

#NOT ENABLING

#config 'rule'

#       option 'src' 'dmz'

#       option 'proto' 'udp'

#       option 'dest_port' '67'

#       option 'target' 'ACCEPT'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;*I chose not to enable a DHCP server on the DMZ network, but did so for the internal VLAN at this time.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# Allow the DMZ to access the Internet

config 'forwarding'

   option 'src' 'dmz'

   option 'dest' 'wan'

# Allow the LAN to access the DMZ

config 'forwarding'

   option 'src' 'lan'

   option 'dest' 'dmz'	
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;issue-with-wireless&quot;&gt;Issue with wireless&lt;/h2&gt;

&lt;p&gt;I had an issue getting wireless to work.  The AP would not broadcast and I could not get the wireless interface to become enabled.  I was getting the following error message:  “Wireless is disabled or not associated”.  I reviewed the file /etc/config/wireless and noted that the “option type” under the wifi device was set to “Broadcom”.  A little research showed that this configuration was a holdover from the brcm-2.4 kernel, however as noted above this was upgraded to bcm47xx.  I was a little concerned about the packages that would be needed to fix this, but as it turns out a resolution was really simple (thanks linuxb - &lt;a href=&quot;https://forum.openwrt.org/viewtopic.php?id=22311&amp;amp;p=14&quot;&gt;https://forum.openwrt.org/viewtopic.php?id=22311&amp;amp;p=14&lt;/a&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rm /etc/config/wireless; wifi detect &amp;gt; /etc/config/wireless
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That resolved the issue and enabled the wireless radio and set up the config file in the following generic way:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/post1/pic9.png&quot; alt=&quot;pic&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To complete the remaining wireless configuration, I used the tutorial on the OpenWRT website ( &lt;a href=&quot;http://wiki.openwrt.org/doc/uci/wireless&quot;&gt;http://wiki.openwrt.org/doc/uci/wireless&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;OK – that’s it for this entry!  Next time we’ll work on setting up some NAT’s and opening up some choice ports.  After that, onto server configuration and then the real fun begins!&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Test Post</title>
   <link href="http://jefbags.github.io/na/2015/06/29/First-Post"/>
   <updated>2015-06-29T00:00:00+00:00</updated>
   <id>http://jefbags.github.io/na/2015/06/29/First Post</id>
   <content type="html">&lt;p&gt;##Hello World!&lt;/p&gt;

&lt;p&gt;This site was built with Jekyll.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/jekyll-logo.png&quot; alt=&quot;test3&quot; /&gt;&lt;/p&gt;

</content>
 </entry>
 
 
</feed>