docker firewall blocking at the source port

March 13, 2018 at 23:18 (Docker, linux) (, , )

Today I installed my brand new docker host system, started some images and as usual trying to setup iptables to restrict the ports to specific source servers and ports.

Hours later I learned that this was kinda not so easy.

  • You cannot use the INPUT chain as Docker works with the standard bridge in the FORWARD chain.
  • The DOCKER-USER chain (which is a part of the FORWARD chain) see packets after they have been redirected to the destination port, so if we have multiple containers running at port 8000 internally it get’s very complex to find the correct container, not to mention new containers starting up.

One example:

I have a docker image that runs a web-server listening inside the container on port 8000 which is mapped to the host port 80 as in this config:

– “80:8000”

This means my host is listening on port 80 and that get’s redirected to the Docker container on port 8000.

Now the DOCKER-USER chain sees only port 8000 where I could drop some other source IP.

But I want to selectively open ports and let not configured ones dropped by default, even if somebody spin’s up new containers.

The docker-documentation and some other sources disable the iptables feature of docker and manually configure the firewall, which is okay but not that what I wanted as the sources allow general inter-container communication or have a VERY complex rulesystem that I don’t want to explain the my Administrator colleagues of that system.


The solution to this is hidden within the iptables flow diagram:

The PREROUTING chain of the nat table is the first one that get touched and where the source port of 80 is redirected to the container on the destination port 8000.

So we tag the SYN packets we want to drop in the PREROUTING chain of the mangle table with the MARK target and later at the DOCKER-USER chain of the filter table we will drop them accordingly.

My final ruleset looks like that:



#Flush and setup:
/sbin/iptables -F DOCKER-USER
/sbin/iptables -t mangle -F PREROUTING

# Docker conf
#packets in NAT table are only traversed with the first packet!
#MARK1: allowed packet
#MARK2: drop this in FORWARDING (DOCKER-USER)Chain
#Mark everything with 0x2, so block everything
/sbin/iptables -t mangle -A PREROUTING -i ens3 -m state –state NEW -j MARK –set-mark 2
# Mark the packets we want to allow with 0x1 (which are previously also mark’ed with 0x2)
/sbin/iptables -t mangle -A PREROUTING -i ens3 -m tcp -p tcp –dport 80 -s -j MARK –set-mark 1
/sbin/iptables -t mangle -A PREROUTING -i ens3 -m tcp -p tcp –dport 443 -j MARK –set-mark 1

# Drop the packets marked with 0x2

/sbin/iptables -A DOCKER-USER -m mark –mark 2 -j DROP
/sbin/iptables -A DOCKER-USER -j RETURN

This ruleset will allow port 80 from a specific IP address and port 443 from every source IP. Everything else exposed by docker containers is not reachable for anybody – or at least they cannot open a TCP connection to it because the initial SYN packets are dropped away.

And the best is I can start as much containers as I want on port 8000 and don’t have to fiddle around with the internal docker ports.

Hope that helps somebody ;)


Permalink Leave a Comment

Gitlab “file changed as we read it”

February 19, 2018 at 19:45 (Docker, linux)

Months after the OSCE and my shiny new OSCP certification, a refactor of the infrastructure and a current build-up of a “Security Operation Center”, I’m fully back at work.

My desk is fullblown with management documents and other shit I don’t want to read, instead I’m looking at my screen after I builded a Docker Infrastructure including a GitLab server:

root@7845ae79a54c:/# gitlab-rake gitlab:backup:create
Dumping database …
Dumping PostgreSQL database gitlabhq_production … [DONE]
Dumping repositories …
Dumping uploads …
tar: ./-/….. file changed as we read it
Backup failed

Hmm, great :) Not only that the gitlab server is no more than a day old, the backup won’t work. Grr.

Long Story short, after a lot of googling my problem was a GlusterFS mount on my docker host which is bound into the Docker container.

The fix is to issue i issued the following commands on my docker host:

gluster volume info
gluster volume set dockergfs cluster.consistent-metadata on

And after a host reboot (or remount just as you like), surprise surprise the backup works now!


If I find more time between my family, my private projects and my daily business I’ll write a review of the OSCP course if there is interest :)

Permalink Leave a Comment

Transparently sniffing and modify traffic with scapy in-path

January 29, 2017 at 19:42 (linux) (, , , , )

I decided to play a little bit with scapy and tried to find something in the internet that helped me to sniff and modify traffic without ARP-Storming the whole network.

I want to connect a box to my computer eth0 and the network to eth1, so that I’m between the box and the network.

Note: This one does not defeat SSL right now, but that could be easily done with all the tools out there.

The idea is to transparently forward all traffic and only pick out specific packets for modification with scapy.

I did do this with an combination of bridged interface, iptables NFQueue and scapy.

First we gonna create a bridge between eth0 and eth1 to transparently forward all traffic:

ifconfig eth0
ifconfig eth1
brctl addbr br0
brctl addif br0 eth0 eth1
ifconfig br0 up

Second, we need to setup iptables to send the traffic we want to change to an NFQueue.
Important is that this line is executed within the startup of the scapy script, so the actual modding only happens if the script is running.
It would be bad if the script is not running and the packets don’t traverse..

The line we need to set in the scapy script is:

iptables -A FORWARD -m physdev –physdev-in eth1  -s -j NFQUEUE

Third, our scapy program catches those packets, modify them if they are of interest for us and forwards them accordingly.
Important is to command scapy that it should also forward traffic we do not want to be modified (e.g. other SNMP calls in this example):

What I actually do is to modify a response of our target system to the monitoring system.
I choose the SNMP response of an HP ProLiant power-supply check that checks if the power supplies are OK or not (or disconnected):

The “original” says that both power-supplies are degraded or in other words they have a problem:

# snmpwalk -v 1 -c public -O eq
iso. 3
iso. 3

# ./check_psu -H

after starting the scapy script, it will happily transform to something much better:

Adding iptable rules :
iptables -A FORWARD -m physdev –physdev-in eth1 -s -p udp -j NFQUEUE
[+] Running Main loop
Got a packet ! source ip : dest:
Old status: 2 (<ASN1_OID[‘.’]>)
New status: 2 (OK)
Got a packet ! source ip : dest:
Old status: 2 (<ASN1_OID[‘.’]>)
New status: 2 (OK)

and in the console:

# snmpwalk -v 1 -c public -O eq
iso. 2
iso. 2

# ./check_psu -H

And this all by just carefully crafting and modifying packets

Have Phun :)

Permalink Leave a Comment

My OSCE / CTP Story

April 3, 2016 at 15:51 (Everything Else) (, )

It was quite a long time since my last post now. That is simply because my family and my job is taking up all my time since the last years ;) The last month I found myself that I need to challenge myself and wished long time ago to get a technical certification in the security sector.

My last certification was quite a lot of time ago and was a Qualys Guard certification so i searched the internet for an adequate challenge to take.

After reading some blogs i found that the certifications from seemd to be really challenging, even for people who worked for years as pentesters.
A bit of reading on the offensive website stated:

“… widely regarded as one of the most respected and difficult to obtain technical information security certifications available, the OSCE is the industry premier advanced penetration testing certification.
Holders of this certification are part of an elite group who have proven they have what it takes to be among the best and brightest in the field.”

Umm making that statement from such a respected company…
I thought this could be really challenging.
So i decided to give the Cracking the Perimeter and the resulting Offensive Security Certified Expert (OSCE) a shot

That said, I found myself over at, the registration challenge for the CTP course.

The first few steps of were quite easy, just because I had managed to get a few levels over at years ago and remember everything of that, the rest you can think of yourself :)

Please be aware that I will not give any hints on the registration challenge / the course or the exam.

The exam is so hard – if you can not make it yourself and need to use hints from anybody to do the exam you are cheating and have not deserved the certificate.

-the CTP course-

You will have an option to register for 30 or 60 days, i chose 60 days and planned to do my exam after about 45 days and if i could not archive it, I could work on the lab for another 15 days and try again.

If you need other information’s about the course itself, give google a shot, there are plenty of reviews on the CTP course itself.

Of course nothing you plan for your life is exactly happening the way you planned before.

I wanted to plan my exam 15th April but on Friday 2016-03-25 my public services provider dropped a letter that they will break up the whole street where I live and maintain power, gas and water for 15 WEEKS, starting the 15th April.

Damnit, so i cannot rely on a stable internet connection for the whole 48 hours of exam.

I then found an exam slot at Monday 28th March – yeah 2 days after I received the letter from public services..

I then scheduled the exam to this date…

As stated before that nothing you plan is going exactly this way, everything is trying to get the hell out of me and my whole family went sick in the night to Monday >:(

Nothing i could do – I couldn’t reschedule the exam and had to do it now.

– the exam –

I can’t tell you how nervous I was. I created a lot of scripts beforehand where I thought Offensec will put me some stones. I even learned python a little bit as I want to get everything I could from the course.

The exam consists of 4 challenges, 2 with more points, 2 with fewer points rewarded.

I started with the smaller ones where even my scripts come handy so my nervousness flattened..
7 hours later I had 3 out of 4 challenges made.

I started the exam at 16:00 PM now it was 1 o’clock. I went to my first sleep.
Wakened up at 8AM I get a coffee and immediately headed over for the last challenge.

This challenge could be broken up in 2 parts and after some fiddling I got the first part working after two hours or so.
But then, this one put everything out of me, I couldn’t get it to do what I want – I worked really hard with some little breaks to regain consciousness.
I found several ways that *could* work, but none of them did work at the end and I started to get frustrated.

It is now 02:00 AM and I went to bed again, couldn’t do anymore..

After a horrible sleep I woke up and the first thing that came to my mind was:
“T-R-Y   H-A-R-D-E-R!”
Okay, got a coffee.. More ideas came…
5 hours later I was really between hope and desperation.
It was now 13:00 and I started to get ready to fail at the last step of the exam.

But not with me, I tried shooting at the dev-target as much as I could and baaam!
Out of nowhere my last idea did work!

Now I started to get really nervous now, I had to hack all my findings together in a working manner and has to circumvent some little problems but I managed to get everything up and working 2 hours before the end of the exam.

Now I was ready to work against the objective and on the first attempt it did work!

YEAH I was so happy that I screamed around and really felt like a hero.

I hacked together my documentation of everything for what i had again 24 hours after the exam but I needed to know if I did pass or not. I had invested soo much hard thinking I couldn’t wait for the result.

After 2 days I got the revenue:

We are happy to inform you that you have successfully completed the Cracking the Perimeter certification exam and have obtained your Offensive Security Certified Expert (OSCE) certification

And they even sent me a nice image to include in my online activities:


In the end I was sooo close to give up, but the moment when you overcome this feeling and get it working is what everybody out there is meaning with the words “try harder” – with enough persistence everything is possible.

Thank you Offensive-Security for this mind-blowing course and to allow me to master success and failure – this was the hardest thing I ever have made under the pressure of time!

Really I need to say thanks to my 2 kids and my wife – they have gone sick but managed to not disturb me the whole 3 days while i took the exam. Thank you :) Love you ;)

Now, the next step is to recon from this and to get my family healthy again ;)

Permalink Leave a Comment

XBEE Ready.

December 9, 2013 at 10:26 (Uncategorized)

Now, in my last Posts i showed you that i use the Xbee Series to play a little bit around.

First of all i tried to design a system that allows me to realize my House Automation.

I wanted to include the Xbee System as this not just helps me to save cables, but enable me doing freaky wireless stuff like remote-open my door or alarming all Xbee Chips at the same time that some burgular trying to do his work.

I had the following things in mind:

  • Xbee Devices are all over the house, encryption on, connected to a Micro like the ATMega32 or standalone (for my letterbox)
  • Communicator is hooked up to a linux system so i can take control from there
  • Xbee’s should communicate with each other, the Computer is just passive

So the following thing is what i need:

1. XBee’s in API Mode
This is a must as only in this mode fast addressing is possible

2. Linux system connected to the Coordinator via FTDI

I had the standard ftdi_sio module loaded with the connected FTDI 232BL, it got’s recognized and i can communicate with the XBee.
After a while i can write to the XBee but my subsequent read’s doesn’t return anything.

While i debugged and changed my Code over two Month’s i found the Problem: The FTDI Chip or the ftdi_sio driver.
I use perl, threads and a lot of other stuff i never used before and searched the Problem there. But i didn’t find anything.
A quick test with an standard RS232 Converter + XBee resulted that my Code is completly OK. >:[ D-A-M-N

3. Preferbly a Perl Script that run’s a a Server
So more than one “Client” can Connect to it and Control everything, for ex. a recurring linux Cron Job checking Temperature and a “GUI” User Interface on Windows should not disturb each other and both should work at the same time.

4. Xbee’s connected to ATMega32
No problems here, ATMega32 have a Serial Interface

5. ATMega32 API
This was not too hard to write, but the Memory Management is tricky..
I learned that i even can overwrite my Memory with BASCOM, so this is no more excuse to not use C ^^


This was written about two years ago, in the meantime i created a system exact like this one, written a perl server and has the XBee’s connected.

Everything is fine until a day where all XBee’s lost it’s connection to the coordinator without an obvoius reason.

I’m still investigating why the Radiochips loose it’s connection, sometimes it takes 3-4 Weeks, sometimes every hour they loose it.

I’m really disappointed about the relaiability of those XBee’s, i thought they will reconnect to other routers but it seems that one XBee is sticked to it’s parent forever.

I’ve written an perl server with jabber and network integration for the System but i discarded it.
At the moment i’m concentrating on an FHEM implementation as I started to head over to HomeMatic :)

More to come..



Permalink 2 Comments

ESXi 5: Expanding datastore by extending local array

April 21, 2012 at 21:48 (VMWare) (, , , , , , , , , , , , , , , , , , )

Recently i extended my RAID 5 array by replacing one-by-one hdd’s with bigger ones and waiting for each to rebuild.

All the instructions are executed on a HP DL360 G6 with an SmartArray P410i controller with only one logicaldisk.

It is highly recommended that you backup all your VM’s before executing a single command – everything worked fine for me but one error in a command could leas to a complete data loss of everything!

Read the rest of this entry »

Permalink 13 Comments

SSL Funambol on Android without adding Certificates

December 26, 2011 at 22:36 (Android) (, , , , , , , , )

Recently I wrote a blog entry about how to add a root certificate to your rooted android keystore for using SSL funambol.
This works perfectly as long as you have root access to the device.

Sometimes you come into the situation where you cannot root the device, eg. in a corporate environment or if you just don’t want to crack a new device just to make the funambol client working, like me for now.

I’ve got a new Motorola Xoom and needed funambol to sync my contacts and calendar entries.

After asking Mr. Google there are only 2 ways till Android 4.x is ready:

  • Using http without ssl
  • Using ssl and recode the funambol client to accept all cert’s

I decided to use the 2nd solution – this also refreshes my java a little bit :-)

Of course i want to share everything with you – if you’re too lazy to read all the stuff you can point your Android client here to install my compiled Funambol 10.0.8 client without the certificate check:

For Android < 4.0 this binary works:

Direct download with android: funambol-android-10.0.8_Tasks-devBioS.apk

Mirror 1: funambol-android-10.0.8_Tasks-devBioS.apk

Since ICS (>= 4.0) people having problems syncing Calender. This is because they made changes in the Calender API wich renders the Calendar Sync unusable, you can use this binary (which only works on ICS and greater):
Direct download with android: funambol-android-10.1.3_Tasks-devBioS.apk

UPDATE 2012-04-03: I activated the task sync feature also and re-uploaded the binary.
If anyone is intrested in the source on how to activate it, drop me a line and i will update the post.

Read the rest of this entry »

Permalink 32 Comments

Adding Root Certificates to Android Phone with root access

August 23, 2011 at 22:24 (Computer) (, , , )

Yeah, after being really busy with my real life, here is another intresting trick for you:

How to get some more root certificates on an android phone where you have root acces (or, at least, you can start & use root explorer).

Some background info:
I use a funabol community server to keep my phone’s and outlook’s in sync and recently my colleague sven did a great job converting my HTC HD2 with winmobile to Android 2.x (kudo’s to him! thanks!).

Update on 2011-12-27: I changed the client to allow self-signed certificates: here

The challenge is that if you use funabol with self signed ssl certificates you need to get those recognized by android which is a really complicated task if you don’t know how.  But here we go:

What you need before (and what i don’t describe):

Our steps include:

  1. Export the certificate out of the funambol java keystore
  2. Get the cacert.bks from the android device
  3. modify the cacerts.bks of android
  4. reboot and finished

Step 1 – Export the funambol certificate

  • Execute  “%JAVA_HOME%\bin\keytool -export -alias tomcat -file myroot.cer”  (in-detail like here)
  • copy the myroot.cer to the SD-Card of the android device (or download to another computer)

Step 2

  • insert the SD-Card to the android device, startup root explorer and navigate to /etc/security/
  • copy the file cacert.bks
  • navigate to /sd-card and paste the file
  • insert to another computer
  • Go and execute the Portecle Keytool and open the cacerts.bks from your SD-Card
  • When promtes for a password, just hit enter
  • go to Tools -> Import Key Pair   and select your myroot.cer, give it any name you want
  • save the cacerts.bks
  • re-insert the SD-Card to android device
  • open up root explorer, head to /sd-card, copy, paste to /etc/security/
  • make sure root explorer show “mounted as r/w” in the header of the program.
  • set permissions of the newly copied cacert.bks to rw-r–r– (owner,group,other: read     owner:write)

Step 3

  • double check if the permissions of cacerts.bks are set correctly to rw-r–r–
  • restart the phone
  • funambol sync should now complete.

Have phun to be in sync!

P.S. Keep in touch! the next xbee’s blogpost’s are half-way written, but i really don’t have time ATM… sry

Permalink Leave a Comment

QuickFix: IE8 hangup opening intranet pages

April 11, 2011 at 16:53 (Windows) (, , , , , )

Something that i always hate is when there is no update and a product stop’s working so i cannot do my work anymore.

In this case i (am forced to) use Internet Explorer to open up several intranet pages that allowed me to do my administration work.

The problem sums like this:

  • Google, and everything else on “the internet” works seemless
  • opening something internal just hang up IE8 for a couple of minutes and then just stop loading without an error
  • Same in FireFox with IETab installed
  • same in IE 7 + IE 8 64 bit and 32 bit

The solution is as easy as stupid:

In “Internet Options”  -> “Security” the “Local Intranet” is set up with disabled “Protected Mode”.
Enabling it fixed
the Problem instantly for IE8, IE7 and Firefox with IETab.

Permalink Leave a Comment

Weekend Project: Connect a letterbox to Jabber with XBee

May 16, 2010 at 19:05 (Electronics, linux) (, , , , , , )

As i promised this is my first XBee Project. I just needed a more or less useful application i can “test” the XBee’s in a real environment.

It is in my nature to do crazy things, so i thought it would be really cool to have a notification Jabber Message to my Phone when someone put some letters for me in my letterbox. Here it is ;)

01-08-2010 Update:
The FTDI Chip gives me A fscking LOT PAIN more to come in the next Post. DO NOT USE IT :)

This is my Setup:

  • XBee “Coordinator” API Mode connected through a FTDI USB Chip to a linux box
  • XBee “End Device” Interfaced with an Atmel ATTiny13v power by two 1.5v AA Batteries
  • Perl XBee Module from Thomas Jager
  • Jabber Perl Modules to enable sending messages
  • Siemens S685IP DECT Phone that can recieve Jabber messages

Before you read further you should note that i flashed the ZIGBEE firmware (XB24-ZB) API on my XBee’s because i don’t want to miss the mesh feature.

This Setup now runs with 2x Alkaline Batterys in the End-Device for 4 weeks now, and is still running!

Read the rest of this entry »

Permalink 4 Comments

Next page »