Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Monday, April 17, 2017

Negative Numbers and Positive Attitude

Negative Numbers and Positive Attitude


I have heard people say that the best age to tell your kids about sex is when they are five. They accept it naturally and youre still able to look them straight in their eyes while going into details. Plus, you know more than they on the topic, and that wont be the case for too long. Well, my six year old daughter has yet to ask me about sex and I am hesitant to volunteer the information. But she just asked me about negative numbers. She did not actually use the words “negative numbers.” She told me that someone at school said that you can take away 3 from 2 and still get something. I opened my mouth to reply that she would learn all this in a few years at school and shouldnt be worrying for now, but looking into my daughters expecting eyes realized mid-sentence how un-educational and betraying this is going to be. You are The The Math Mom, and should grab this opportunity. Surprisingly, a curious analogy popped out in my mind. Different flowers reach different heights, which we can measure with a ruler. But what are we going to do with carrots? They grow downwards, in the opposite direction from the flowers. Continuing the measurements down, we step from 0 to -1, and then to -2, -3... We marked our hand-drawn carrots with their “negative” length. My daughter looked satisfied. I looked proud and self-satisfied.


Of course, a couple of minutes later she claimed that 60-60 = 10 and I mused that she should go work at the bank and do such magic there. For better or worse, I believe that such attitude is a very important quality we can and should be shaping. Presenting math as fun: playful and interesting. Sharing our daily math encounters with kids. Discussing puzzles at the dinner table. Demonstrating our confidence in kids achievements and implanting the desire to succeed. But we have to start early, we wont know more than our kids for too long.

What scientists are saying:
A number of scientific studies have demonstrated that cultural and environmental factors, and not intellect, are what limit womens achievement in math. Link to the most recent study review in Boston Globe. Another study has shown that boosting self-confidence just before a test, reminding students how well they did it last time and are expected to do again, results in a significant performance improvement. And, conversely, mentioning to students a possible negative disposition that they might have inherited, leads to an immediate drop in performance.

Whats in the logo?
What do you think about the new The Math Moms logo? Designing the logo, we were hoping to make it inspirational and non-stereotypical. This is you, sitting on a kitchen chair, thinking numbers and enjoying The Math Moms stories and puzzles. We hid at least 10 numbers inside the logo. Print this image and use your kids help to find all of them.

Read more from The Math Mom. Here is a story about hip math of shopping.



Available link for download

Read more »

Saturday, March 4, 2017

Not So Random Numbers Take Two

Not So Random Numbers Take Two


George Argyros and Aggelos Kiayias have published recently an awesome research concerning attacks on pseudo random generator in PHP. However, it lacked practical tools implementing this attack. That is why we conducted our own research which led to the creation of a program to perform the bruteforce of PHPSESSID.

How can we get mt_rand seed via PHPSESSID?


PHPSESSID is generated this way:

md5( client IP . timestamp . microseconds1 . php_combined_lcg() )
  • client IP is known to the attacker;
  • timestamp is known through Date HTTP-header;
  • microseconds1 – a value from 0 to 1000000;
  • php_combined_lcg() – an example value is 0.12345678.

To generate php_combined_lcg(), two seeds are used:

S1 = timestamp XOR (microseconds2 << 11)
S2 = pid XOR (microseconds3 << 11)
  • timestamp is the same;
  • microseconds2 is greater than microseconds1 (when the first time measurement was made) by 0–3;
  • pid is the id of the current process (0–32768, 1024–32768 on Unix);
  • microseconds3 is greater than microseconds2 by 1–4.

The greatest entropy is contained in microseconds1, however with the use of two techniques it can be substantially reduced.

Adversarial Time Synchronization


The technique is aimed at sending pairs of requests so that to determine the moment when the second in the Date HTTP header changes.

HTTP/1.1 200 OK
Date: Wed, 08 Aug 2012 06:05:14 GMT

HTTP/1.1 200 OK
Date: Wed, 08 Aug 2012 06:05:15 GMT

If it happened, the microseconds between our requests zeroed. By sending requests with dynamic delays it is possible to synchronize local value of microseconds with the server one.

Request Twins


The principle of this technique is simple. The attacker needs to send two requests: the first one — to reset their own password and the second one — to reset that of an administrator. The gap between microseconds will be minimal.

To sum up, an MD5 PHPSESSID hash is bruteforced for microseconds, the deltas of subsequent time measurements, and pid. As for pid, the authors have not mentioned such a great helper as Apache server-status which reveals among other information the pids of the processes which serve the requests.

To realize the bruteforce, a module for the popular program PasswordsPro has been initially created. However, this solution made it impossible to take into account the positive linear correlation between deltas of microseconds, so it bruteforced the full range of values. The speed was about 12 million hashes per second.

That is why we created our own GUI application for this task.


The speed is about 16 million hashes per second, seed calculation takes less than an hour on 3.2 GHz Quad Core i5.

Having pid and php_combined_lcg one can compute the seed used in mt_rand. It is generated this way:

(timestamp x pid) XOR (106 x php_combined_lcg())

Besides, php_combined_lcg is used as additional entropy for the uniqid function (if it is called with the second argument being true).

So, if a web application uses standard PHP sessions, it is possible to obtain the random numbers generated via mt_rand(), rand(), and uniqid().

How can we get mt_rand seed through one of the random numbers leakage?

The seed used for mt_rand is an unsigned integer 2^32. If a random number leaked, it is possible to get the seed using PHP itself and rainbow tables. It takes less than 10 minutes.
The scripts to generate rainbow tables, search the seed, and ready-made tables are available here: http://www.gat3way.eu/poc/mtrt/


What to look for in the code?

All the mt_rand(), rand(), uniqid(), shuffle(), lcg_value(), etc. The only secure function is openssl_random_pseudo_bytes(), but it is rarely used in web applications. The main ways of defense against such attacks are the following:

  • MySQL function RAND() — it can be also predicted though.
  • Suhosin patch — does not patch mt_srand, srand. The Suhosin extension should also be installed.
  • /dev/urandom — the securest way.



Arseny Reutov
Timur Yunusov
Dmitry Nagibin

Available link for download

Read more »