Showing posts with label cybersec. Show all posts
Showing posts with label cybersec. Show all posts

Saturday, July 26, 2025

"INTs Aren't Integers and FLOATs aren't Real"

 

                            I was told this is a cat-submarine. Tail = Periscope. I believe it.
 


Over the past few weeks, I’ve been juggling two realities. On one side work: networks, and the daily exploration of security tasks in a banking environment. On the other, low-level code: free time, NASM, one instruction at a time.

 

I’ve been reviewing the basics—x86 syntax, memory layout, data definitions, etc etc etc. I'm following a series of videos, from a YouTuber that I appreciate, and although I found some information lacking or imprecise—particularly in the episode devoted to divisionit's still a good set of videos and I'd advise anyone to watch them here. Lately I've taken a gander at integers. How they’re stored, manipulated, compared, and what all those flags mean when you're moving bits around and trying to make sense of a program in GDB.

If you’ve spent more than a few hours in GDB (as I have, unreasonably so at times), you’ve probably done a CMP eax, ebx and then wondered what exactly happened to the flags. What’s the deal with CF, ZF, SF, and the rest of the alphabet soup? Why do certain jump instructions follow CMP, and not others?

So, quick refresher for the two family members that like me and still read this blog:

CMP just subtracts the second operand from the first, sets flags, and discards the result. The flags tell you the outcome, and then you pick the jump based on what you want to test.

InstructionMeaningFlags checked
JE / JZEqual (zero result)ZF = 1
JNE / JNZNot equalZF = 0
JL / JNGELess than (signed)SF != OF
JLE / JNGLess or equal (signed)ZF = 1 or SF != OF
JB / JCBelow (unsigned)CF = 1
JAAbove (unsigned)CF = 0 && ZF = 0

Notice those signed vs unsigned differences? JB isn’t "jump if smaller", it’s "jump if below"—unsigned. If you’re comparing signed ints, you should be using JL, JG, and so on.

Floats make it even more nuanced. UCOMISS xmm0, xmm1 for example, is how you compare scalar floats. That instruction sets flags similar to CMP, but works with IEEE 754 single-precision values, not integers. And yes, it’s aware of signs, NaNs, Infs, and the rest (of floating point hell).

Anyway, all that to say: this is kinda subtle, or at least it requires some study and care. IMO, totally worth learning. Most would disagree profoundly. I’ve been pushing myself to remember it, slowly but deliberately. You can check out some of the tiny experiments here. It’s not a project, more like a scratchpad that runs on opcodes and (lovely, quality) coffee.

 

                                                                 ...When in doubt, explain it to me. I'm anathema too.


 And you know what's fun? Mathematics! No, really.
I've seen it again and again: people treating floats as if they are basically the real numbers
(ℝ). They aren't!

Just take a look under the hood and you'll understand why.

"But OPQAM, I use Python/Java/Whatever. I don’t care about Assembly or floating-point registers!"

And that’s fair—until you try 0.1 + 0.2 and get 0.30000000000000004, or even 0.30000001192092895508. Then it might matter.

Can you think of a situation where such a small discrepancy could be a problem? I sure can. I can think of several, and some of them imply falling bridges.

Here’s the core issue: ints aren’t integers, and floats aren’t rationals.

 

An example

The decimal 0.1 becomes the binary: 0.0001100110011001100110011001100110011..., repeating infinitely.
But computers can’t store infinity. They cut off after some number of bits: ~23 bits for floats, ~52 bits for doubles. It’s like trying to store 1/3 in decimal — you can’t write 0.3333... forever. You round. You approximate. So do computers.

So, this means that you cannot represent 0.1 precisely.

 

The problem isn’t the mathematics — it’s representation.

How do systems and programmers deal with this?

  • Use decimal representations (decimal.Decimal) when exactness matters (e.g. money).

  • Use rational types that store fractions exactly (Fraction(1, 10)).

  • Use symbolic math when precision must be preserved throughout (SymPy, CAS software).

  • Or use fixed-point arithmetic — store cents instead of euros.

These are workarounds. The real solution? Know that floats are approximations, not truth.



                                                Accurate depiction of my two family members' faces as they read through this.


Meanwhile, back in the Real World, there was a CTF going on in the team. A colleague of mine created it and invited us all to some friendly competition for the next few weeks. Honestly? I will probably only do a couple CTFs before I turn my attention elsewhere. Having a family + hobbies + a day job does limit one's time. Still, I got to dip, and I managed to solve a challenge involving a simple—but satisfying—privilege escalation. I'm not going to give a lot of details, since it goes against the point of the 'contest' and it's actually requested by the site that we don't do it. But here's the 'trick': Classic PATH hijack. I dropped a fake ls binary into a writable dir (/tmp), positioned it early in $PATH, and executed the vulnerable binary which, instead of ls executed cat. Bang. Root shell. Dump flag. Walk away smiling.
This was, of course, allowed by purposefully using SETUID in the binary. A no-no. But there you have it. It was fun.

And yeah, sure—it’s not the most sophisticated vector ever, but the fact is, simple stuff works. You don't have to be fancy-schmancy to make something give you a 'win'. It is thus in Jiu Jitsu, and in illusionism. And so it is in hacking.

Also worth noting: a few days ago I got into a discussion with a colleague about TPM (Trusted Platform Module). I’ve blogged about the TPM issue here, but here’s the gist of it: I had to disable TPM on an old laptop (a very respectable ThinkPad x260) just to make the thing actually power off correctly. I tried everything—kernel parameters, ACPI tweaks, prayer (not really, but I totally could have!)—but nothing worked. Full shutdown always left the machine 'hot'.

Disabling TPM did the trick.

Why? Long story short: the TPM implementation on that hardware was tailored for Windows, and Linux support is... charitable at best. As for the discussion. That colleague warned me that in certain scenarios, like full power drains, I could end up with an unbootable machine if I lost TPM state. So I did what any sane people would do: I tested it again and again, simulating different scenarios.

 

Unplugged, drained, every scenario short of desoldering the CMOS battery. Result? Nothing broke. LUKS doesn’t need TPM. At least, not for the way I have this set up. In Linux, with this setting, TPM is optional unless you're deliberately tying encryption keys to it—and even then, tread carefully.

These tests were fun. They reminded me of the joy of breaking things on purpose, and the calm that comes with understanding exactly why something behaves the way it does.

So yeah, life’s been busy. I haven’t had much time to write (sentence never written by any amateur blogger ever). But I’m still here, still learning, and still hacking away.

Next up? I'll probably hit you up with some more ASM stuff as I keep on watching those videos and experimenting with stuff. Maybe some CTFs... who knows? Not me! And I'm right here. 

We’ll see.


Wednesday, April 23, 2025

How a Spy Pixel Crashed Into My Friend's Vacation

 

         So it goes.

 

A friend of mine, a freelancer, recently went on a much-deserved vacation. Like most of us in today's always-on culture, she left an automated "I'm away" response on her email.

One day, she received a message from a client. Curious whether it might be urgent, she opened the email — but chose not to reply. A few hours later, she received another email from the same client:

"I know you opened our email. Can you please answer to our job offer?" 

Creepy material right there.

How in two hecks did the client know that she had opened their email and read their message, without her replying? The answer is tiny, technically invisible, and fascinating — a spy pixel!

 


                 There's totally a Spy Pixel there, trust me bro.

 


But what are they?

 

A spy pixel is a tiny, invisible image that gets embedded in emails. Usually just a 1x1 pixel, fully transparent, and basically impossible to spot by just looking at the email.

The moment your email app loads it — boom — it sends a signal back to whoever embedded it.

What's in that signal? Well, I'm glad you asked. It can include, at the very least:

- Your IP address (which can give away your rough location),

- The exact time when you opened the email,

- Your device type, OS, maybe even your browser,

- Whether you opened it multiple times or forwarded it to someone else.

 Here's her little spy:

<img src=3D"https://app.frontapp.com/api/1/noau= th/companies/5faa110782efdfc2d885/seen/msg_uugvds6/0/0a5b6123.gif" alt=3D"S= ent from Front" aria-hidden=3D"true" style=3D"width: 1px; height: 1px">

That image isn't there to show anything. It's there to quietly send metadata back to the pixel's creator.


Where and when are these buggers used?

 

You might be surprised they're everywhere in digital communications. Here are some common uses:

  • Email newsletters and marketing campaigns, to track open rates,
  • Sales outreach tools, for engagement tracking,
  • Transactional emails, just to confirm delivery.

But also in more questionable cases:

- Stalking or surveillance by controlling or manipulative individuals,

- Aggressive sales tactics, that cross boundaries (case in point: my friend),

- Phishing campaigns, to confirm which addresses are active.

And, for the most part  barring some exceptions  this stuff is completely legal.


Fear-mongering

 

I love some areas of cybersecurity, but I'm definitely not a fan of the constant fear-mongering I see everywhere.

This stuff is genuinely cool! And interesting. And did I say cool? But it has its downsides. Serious ones, especially when you are on the receiving end of it. Most people don't know these pixels exist, let alone how to block them.

 


                         I B Nautghy!

 


Action.

 

Are we allowed to lie to protect our privacy or avoid annoying people? I think we are. But that becomes hard when someone throws back:

  • "We know you were at your computer yesterday."
  •  "You say you didn't see our message, but we know you did."
  • Or you try to browse anonymously, and the pixel exposes your location

This little guy can enable social engineering attacks by confirming your device type, when you were online, even whether you forwarded the email.

And, all that advice about "not clicking suspicious links"?

You didn't! You just opened the email. And that's all it takes


You gotta fight, for your right. (to party)

 

Thankfully, we've got defenses. Here are some of the basics:

  • Block remote images in your email client (Thunderbird, ProtonMail, and others do this by default),

  • Use privacy-focused email services that prevent images from auto-loading,

  • Browser plugins like uBlock Origin can help if you're using webmail,

  • Use a VPN to mask your IP and location,

  • Or go hardcore and view emails in plain text only.

Just a heads-up: many mobile apps load images by default unless you manually turn that off. And in some cases, you can’t.

 

         Oops...


DIY Spy Pixel.

 

Want to try one for fun? Here’s a simple experiment:

  1. Host a transparent 1x1 GIF or PNG on your own server.

  2. Log image requests using your server (e.g., Apache, nginx, or a basic Flask script).

  3. Add this to an HTML email:

<img src="https://yourdomain.com/tracker.gif" width="1" height="1" />

  1. Send it to yourself.

  2. Open it and check your logs — you'll probably see something like:

    • IP address

    • User-Agent string (your OS, browser, etc.)

    • Timestamp

Research how to do this stuff if it’s new to you. It’s a great little exercise and can be done in an afternoon.


Beyond the Pixel

 

Our tiny spy pal isn’t alone.

There’s a whole army of sneaky tools out there:

  • Link shorteners with tracking redirects,

  • Invisible iframes embedded in webmail,

  • Email fingerprinting, using subtle code to track opens,

  • Read receipts in platforms like Slack, Notion, and LinkedIn.

Once you notice this stuff, it’s everywhere.


A final dot.

Have fun exploring. Even if this isn't your favorite cybersec topic, it's a fun rabbit hole and might lead you to some unexpected discoveries.

 

And as always enjoy the ride.

 

 

"INTs Aren't Integers and FLOATs aren't Real"

                                     I was told this is a cat-submarine. Tail = Periscope. I believe it.   Over the past few weeks, I’ve be...