Have you been in the situation where you start an app and want to intercept network traffic because you are curious what messages are exchanged between the client and the API? So you spin up mitmproxy, charlesproxy, burpsuit or whatever and you see.. nothing?? Hmm, that might be because certificate pinning implemented in the client. Luckily there are some methods to bypass that. One method, that sometimes works for Android apps is to patch the app.
My preferred way to get an APK from an Android device (for reverse engineering purposes etc) is this helpful bash script. No root required, adb installed, phone in developer mode.
This steps generates smali code. Smali is an assembler for Dalvik Virtual Machine bytecode; The assembled dex (Dalvik executable) bytecode can be decompiled into smali code. That’s what we are doing now.
Ok, now that we have the smali code, we can start browsing where the app checks the x.509 certificate. “checkClientTrusted” and “checkServerTrusted” are really good candidates. We patch those two functions to return before the actual check executes by adding “return-void” (line 453 and 467)
apktool b targetapp -o modfied_targetapp.apk
First, we generate a key and then we use jarsigner to sign the apk
The smart fridge is here! No displays, no stupid useless functionality – but precise temperature control and monitoring.
A Fridge is a very simple device. It’s a refrigerating compressor that is turned on and off by a thermostat. Turing on the compressor leads to a drop in temperature, which is monitored by the thermostat. If the target temperature is reached, the thermostat cuts the 230V power and the compressor turns off. Naturally, the temperature is rising again and the cycle start all over again.
This temperature range between compressor on and off is not precise enough for our needs. Therefore, we will replace the old thermostat with a microcontroller and a relay. As a nice benefit, this also allows us to monitor the temperature and change the target temperature from remote.
Part 1: Hacking the Fridge
If you want to learn more about how a fridge works, checkout https://www.brewpi.com/fridge-hacking-guide/. Most of this sections part is identical to the guide above and they did a really good job describing how fridges work.
2x DS18B20 Temperature Sensor
2x XLR 3-Pin Connector pair
Wemos D1 mini
USB Power Supply
Solid State Relay
Silicone for insulating and closing the old cable hole of the thermostat.
1x 4K7 Ω Resistor
Replacing the old thermostat with a Relay
Time to rip out the old thermostat:
For easy cleaning, we want to make the temperature probes removable. XLR connectors are a cheap and reliable way to attach sensors if you only require 3 lines. An advantage of using DS18B20 sensors is, that they are using a 1-wire bus. That means we can add many sensors and still require only one long cable from the fridges connector panel to the controller board.
Part 2: Building the Controller Board.
The controller board is in charge of monitoring the 2 temperature probes, reporting the temperature values to the cloud and of course, switching the compressor relay.
Our main controller, the Wemos D1 mini is based on an ESP8266 SoC, has multiple GPIO Pins exposed and WiFi onboard. This allows us to add more sensors later. For example, we could add an MHZ 19 CO2 Sensor into the fridge to check when the fermentation started without opening the door. But for now, we only need 4 of those pins to control our smart fridge.
1 Pin for a status LED to check the current status and inform about problems.
1 Pin to add a button for simple control like resetting, thermostat on/off, enter configuration mode etc..
1 Pin for the temperature probes. We are using digital temperature sensors (DS18B20) and a 1-Wire protocol, so we can put multiple probes on one pin.
Relay to control the compressor.
Part 3: Software Setup
After flashing the Wemos with the standard “sonoff.bin” build of Tasmota, we are ready to create the rule set for the thermostat. But first, let’s check if the temperature probes are working. We can go the easy way and use the built-in web interface, the serial console or we can do it more complicated. Like this:
Now that everything is running, let’s configure the thermostat. For this, we need to set some basic configuration. We use the backlog command to queue and execute all settings together. This avoids restarts.
SwitchMode1 3: Configure the switch to send a toggle command when the switch is released
Rule 1: Turn on rules
Rule 4: turn off one-shot rule
TelePeriod 60: MQTT telemetry interval sent every 60 seconds. This includes the temperature sensor data and will trigger the thermostat later.
SetOption26 1: Use an index on the relay. If we receive an MQTT message, tasmoa will know which relay to switch and use POWER1 instead of POWER
SetOption0 0: Disable saving the power state, because…
poweronstate 0: …after a restart, the relay should always be off.
mem1 0; mem2 18; mem3 16: We can store up to 5 variables in the flash memory. mem1 is used to enable (1) or disable (0) the thermostat. This can be set by MQTT: Publish a 1 or a 0 to cmnd/sonoff/mem1. mem2 and mem3 are the upper and lower setpoints of the thermostat.
var1 0: This is a variable, which allows us to check it the thermostat is usable. 1 means OK and 0 means not ready. Subscribe to cmnd/sonoff/var1 to check the status. A reason why the thermostat might not be ready is, that the temperature sensor can’t be found.
The groundwork is done. Let’s create a rule. You can configure up to 5 rules; we are using Rule1. It’s simple, you create one big line with all the conditions and actions:
Rule1 on system#boot do RuleTimer1 70 endon on Switch1#State do event toggling1=%mem1% endon on event#toggling1=0 do mem 1 endon on event#toggling1=1 do mem 0 endon on Rules#Timer=1 do backlog var1 0; RuleTimer1 70; power1 0 endon on tele-DS18B20-1#temperature do backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% endon on event#ctrl_ready>%mem1% do var1 0 endon on event#temp_demand>%mem2% do power1 %var1% endon on event#temp_demand<%mem3% do power1 0 endon
Rule1: Use Rule1
on system#boot do RuleTimer1 70 endon: When the systems starts, start a Timer that either evaluates the rules or only Rule1. If you can figure this out, let me know in the comments.
on Switch1#State do event toggling1=%mem1% endon: The moment, the state of Switch1 changes,
Part 4: Using it!
The setpoints can be controlled either by using the built in webserver or MQTT. The webserver has a virtual command prompt. To set the thermostat to an upper setpoint of 18 degrees Celsius and a lower setpoint of 16 degree, write
Finally, if not done yet, write
to activate the Thermostat. Alternatively, you can also press the button on the control board once.
AAAAAAAND here we come to a stop. The summer semester 2019 has ended and the rooms are locked down until winter semester. Everyone let’s go to the beach! This post will hopefully be continued soon. Stay tuned!
I wanted to document the steps that are necessary to transform the Adafruit Bluetooth LE Friend (https://www.adafruit.com/product/2267) to an passive Bluetooth 4.0 Low Energy Sniffer device. This sniffer can be used to monitor the bluetooth communication between 2 LE devices. Which makes it a useful and cheap tool for security research and development.
The Bluetooth LE Friend comes in 2 versions – one with a preinstalled Bootloader, Softdevice and Application to control the on-board Nordic nRF51822 chipset using AT Commands. This Is already really useful for prototyping your own bluetooth applications. It supports OTA updates and Adafruit provides an Android application together with some demo projects.
SWD Programmer (In this example, we are using the STLink V2)
Adafruits Adalink Tool
Step 1: Wire up your programmer
I’m using the STLink V2 SWD programmer (the white box).
You need to connect 4 lines to it.
Target Voltage for sensing (Green)
Now, you need to connect those lines to the SWD connection pads on the bottom of the PCB of your LE Friend. Soldering them on is the fasted way in my opinion.
Note that we don not need to connect the reset pin – the reset is done via the SWDIO line.
Step 2: Prepare
For simplicity, you’ll flash the LE Friend using Adalink. (https://github.com/adafruit/Adafruit_Adalink). Adalink is a python wrapper for OpenOCD that abstracts away the complexity of OpenOCD – which is good and bad a the same time.
The Booloader (https://raw.githubusercontent.com/adafruit/Adafruit_BluefruitLE_Firmware/03110f6819d2e8c0928ce1f3879df22dab562447/bootloader/bootloader_0002.hex)
The Sniffer Firmware (https://raw.githubusercontent.com/adafruit/Adafruit_BluefruitLE_Firmware/03110f6819d2e8c0928ce1f3879df22dab562447/sniffer/1.0.1/ble-sniffer_nRF51822_1.0.1_1111_Sniffer_No32kHz.hex)
Save those files – you’ll need them in the next step.
Step 3: Flash the firmware
Connect your Programmer with your computer and Plug the LE Friend into USB – This powers the nrf51 – the programmer alone does not provide any power to the LE Friend.
As I said, I’m not a big fan of abstracting complicated tasks away from the Hacker: A look under the hood of Adalink reveals what it does. Based on your programmer, it loads the necessary target and board configuration (the -f flags) and executes a bunch of commands (the -c flags). The call above results in 2 subprocess calls:
1: The wipe command in adalink for the stlink adapter:
I needed a lamp. And I wanted to build it myself. I’ve found a couple cool lamps on Thingiverse, but the one I liked provided unprintable, broken models. So I started Thingiverse and built my own model.
For the wood, i’ve used 5mm square mahogany timber from my favourite art supply store Modulor.
The setup consists of 2 layers with 5 leds each. Those chip leds get really hot, so they need some heatsinks. A 3D printed socket for the leds holds the heatsink in place. You can download the .stl here.
For those who missed it – the 33rd Chaos Communication Congress took place from 27.-30.12.2016 – and it was the last one in Hamburg. And I got a ticket. I haven’t seen a lot of talks, because I spent most of my time walking around the hack area and talking to people. But here are some of the talk highlights that I can recommend:
1: Shut Up and Take My Money! – The Red Pill of N26 Security
…or how a broken authentication system could lead to corrupt transactions.
2: SpiegelMining – Reverse Engineering von Spiegel-Online
I’ve built an IoT button a while ago. I’ve also written a short log of the project on hackday.io
The ESP8266, which is used here, is a small, WiFi-enabled chip which can be programmed. I hooked it up to send web request to IFTTT to trigger actions.
I started with a prototype on a ESP8266 NodeMCU development board. The button causes the ESP to send a web request to IFTTT, which is configured to send a push notification to my iPad in this example, but can trigger nearly any action that is supported by IFTTT.
after testing the firmware on the development board, I flashed it on the chip and put everything together.
IFTTT SmartButton from the inside.Tada! We do now have a battery powered push button for the internet of things.
I did this small project on a summer weekend in 2015. I just saw the movie “the Social Network” where Marc had this idea of rating girls using an algorithm called ELO which is actually used for rating chess players based on their wins and losses against other players.
Personally, I think rating girls is disgusting. But rating Bananas and Apples is fine. An I’m more interested in the theory and the Algorithm itself. So I thought, hm, how hard could it be to implement a system like this – turns out: not that hard.
Short theory of the ELO algorithm:
The ELO Algorithm is a very simple, but effective rating algorithm. Assume that we are in the world of fantasy curling players. Naturally there are good players out there with a high reputation and a high chance of winning, and not-so-good players wich are less likely to win a game against the big fishes. Let’s also assume you are a medium level player with a ELO number of 30. The best player has a ELO number of 70. Today is the big day and you will play a match against Player 2 with a rating number of 61. The rank list right now looks like this:
Player 1: 70
Player 2: 61
Player 3: 32
Player 5: 10
Player 6: 2
According to the rules of fantasy curling, there has to be a winner and a looser – a remi is not allowed. At the end of the day, you either won or lost. The outcome of the match will affect both players ELO ratings. The more unlikely the win is, the more impact on the overall rating table this match will have. Let’s have a look at both possibilities.
Option 1 – You will loose
To calculate the new ElO ratings, you have to understand how the Algorithm works. You only need to calculate the expected point difference of one player, because of the simple fact that
R_A and R_B are the current “pre-match” ELO ratings of Player A and Player B.
E_A is a value between 1 and 0. The 400 you see here is a historic value chosen by a guy named Arpad Elo and is since used for the chess rating system. Surprisingly, fantasy curling uses the same value ;-). But feel free to modify it.
So you lost against Player 2 with a rating of 61, which leads to the E_A value for you of 0.4555054269169921. (This is close to 0.5 wich would mean that the parameter 400 is not idea, but works for our example. I would suggest choosing a smaller value if you working with ELO ratings that close to each other.) According to the rule, your opponent has an E_B of 0.544494573083008.
How does that value generate the new ELO rating?
This is actually even simpler:
Your new ELO number will be your current rating (30) plus a factor k (assumed 10) multiplied by the difference of the S_A value (0 , because you lost, 1 otherwise, 0.5 for a draw, which does not exist here) and your just calculated E_B value: 25.444945730830078.
Player 2 now has a new ELO number of 65.55505426916991.
The k factor defines the impact of the match on the game. The higher the k is, the more impact it has. You can also fine-tune here.
Option 2 – You win:
for the unlikely case of a win against one of the leaders of the list, we will result in the following ELO numbers:
Player 2: 55.55505426916992
You : 34.55505426916992
The impact of the match on the table is defined by the constants k, the constant value 400 and the point difference of the opponents (which is variable). The whole systems is based on the simple assumption that games between a higher rated player and a low rated player are more important and have a greater impact on the result. This allows new players wich usually start with an average value to climb up the ladder very fast.
Similar to our example, Facemash also some kind of system with rounds where 2 opponents can either win or loose a match. Every element starts with a basic value of 2500 rating points. As a user, you now decide who wins the round and the ELO algorithm decides the new value.
Matchmaking is implemented to be random.
It’s a very simple way to get elements in some kind of order. I was actually surprised how well it works.
The face mash clone is written in Python and uses Flask as underlaying framework.
the Secret Santa Project was one of my favourites during the time at university. It’s a kiosk-like service for sending anonymous SMS messages with the goal to surprise your friends with a chocolate santa. The chocolate part makes it even better.
Background and motivation:
At university, I was a volunteer at our local UNICEF university group. In winter semester 2013, we had the task of doing a project that has something to do with Christmas – and in the group we came up with a little game: The original intention was to create a kiosk like interface, which students can use to send anonymous messages to a fellow student and inform them, that he or she just received a little present (we got some chocolate form our sponsor).
Let’s assume you want to suprise your close friend – she’s still stuck in a boring class about business administration.
Go to the UNICEF stand in the hallway, say hello to the people in the unicef shirts and type in the kiosk system:
the name of the lucky recipient
the mobile-number or email address
a short message
Check the checkbox if you want to add a personal message pinned to the Chocolate-Santa
Be kind and maybe donate some coins you found in your pocket (because there will always be change for the bar visit the night before and who puts change back in the wallet anyway)
Every message will be logged in a database, but only be marked as ‘sent’ when we know the message was sent out successfully.
She will receive the message via SMS or email including a pickup code! This message is anonymous and will not contain the name field. Even if you entered your name in the sender-field.
She will pick up her present at the UNICEF stand in the hallway. Therefore she tells the people in the blue UNICEF shirts her pickup ID (It’s the last 4 digits of the SMS)
They will then type the ID in the searchfield and set the checkbox ‘delivered’. TADAAAA: you just sent an anonymous secret chocolate santa!
Every message sent out contains a 4 digit pickup code (the lenght is configurable btw).
The Management view of the system looks like this: not a s pretty, but practical:
As a little gimmick, I recently added a small dashboard to keep the motivation of the group at the stand up and tracks their progress with 2 simple values:
We now did this project a couple times and It was totally worth it – besides It was a great learning experience, we had a lot of fun planning the events.
If you like this project, give it a star on GitHub 🙂
THI Timetable is the inofficial Timetable for Students of Technische Hochschule Ingolstadt. It brings your schedule to any device via iCal without having to install an App – you can use your native calendar application!
Background and motivation
Although the university provides a working system, it lacks important features like export or sync functionality. Additionally, the usability is poor: It is written with JSP, making it slow. Another Problem is the layout, which is not optimized for mobile devices. The most annoying aspect of this system is, having you to sign in each time you want to check your timetable.
First I had to analyze the original page. A great tool to look under the hood of a webapp is a browserextension like Firebug. The first step was to reverse engineer the login process to obtain a valid session-id. The prototype of the autenication method looked like this:
Next step is to feed it with username and password and it will send a request to the hiplan-app, parse the result using a regular expression and return the session-id. Now we are logged in, we can dig a little deeper. The hiplan-app uses Ajax to load background-data which turned out to be valid JSON. Fancy! Next we have to parse it. We just transformed the event-jsons to objects, so we can use them to export to any format we want – in this case iCalendar-Format. There is a nice python-library called icalendar which gets the job done. So – next step is to combine all these results and create a first version as a commandline tool. It is available on Github. Just have a look at the examples.
Since the goal is to make this tool accessible to the masses and considering the fact that nobody uses python command line tools, we need a better looking, user-friendly interface. There are several options:
stay on the commandline-way: small user-base
Native Apps: Need support for iOS and Android and Windows Phone (just kidding – windows phone was already doomed to fail back in 2014 when I started the project)
Webapp: Need only one Version for multiple devices / easy to maintain
So I decided for the Webapp. I hosted this service on Googles AppEngine, since it includes everyhing I need: a Python-Webframework called webapp2 that comes with a jinja2-like template system, a data storage which is needed to hold the user data and last but not least probably the most important part: A cron-service to schedule tasks. The system is build on a polling mechanism to scrape the calendar data from the hijacked api, therefore I needed the cron-service to schedule the update-tasks.
If you signed up successfully with your university credentials, your calendar gets parsed for the first time. You will see a success message and a copy-paste text field with a unique url that contains a long, random looking number. This url will point to your calendar in ICAL-Format – a Format which is readable by most native calendar software like google mail, Apple iCalendar, Android etc.. You simply need to pass this link to your calendar software and it will sync on a regular basis. If everything worked as expected, you should see something like this: