Marc Barilley

26 mars 2010

JMeter performance: the “if” case

Classé dans : testing — Mots-clefs :, , — admin @ 18 h 14 min

JMeter is a powerful tool to make tests. See here: http://jakarta.apache.org/jmeter/ for an official description.

Here at work, we use it for multiple purposes:

  • non regression tests : a bunch of JMeter test files containing single use cases  are run to test the commits to the CVS and see if anything has been broken by the changes
  • performance tests : our front or back-end servers are stressed by JMeter test files ran from a dedicated injection server, spawning dozens of threads and getting their data from big CSV files

Recently, I came into a problem: JMeter was running very slowly. Where I expected something like 800 requests per seconds, it delivered only 3 or 4, which is quite low… After some research, I found the culprit: an “If” condition, evaluated at each request. By default, it uses a JavaScript syntax and, apparently, a JavaScript interpreter too. And this interpreter seems to be re-instantiated each time the condition is evaluated! This was why it could deliver so few requests per second.

I tried to bypass the JavaScript interpreter and checked the little box named “Interpret Condition as Variable Expression” and used the __jexl() function. And I nearly got the rate I expected at first.

Done.

6 mars 2010

Intruded narnia level 2 – Part 2

Classé dans : Computer security — Mots-clefs :, , — admin @ 16 h 02 min

I found something on the net but it’s written in Korean. Which I don’t speak…
There’s some asm code in there and I’m trying to understand what it does. I’m still learning and, as soon as I have a clue on how this works, I’ll tell it here. See you soon…

27 février 2010

PHP: optimization tips

Classé dans : web programming — Mots-clefs :, — admin @ 14 h 29 min

A list of some tips I use in my every day work:

    • don’t use count() in for loops.
      // declare an array $a=array(); // fill the array for ($i=0; $i < 10000; $i++) {    $a[]=$i; }   // this is far not optimal for ($i=0; $i < count($a); $i++) {    echo $a[$i]; } // this is better $c=count($a); for ($i=0; $i < $c; $i++) {    echo $a[$i]; }

      Why is the last loop faster than the previous one? Because here, count() is evaluated only once. Indeed, in the previous loop, count() is evaluated each time the loop is run. That is 10000 times!

      • Use the PCRE functions instead of the EREG, they are faster
      • Use the multi-parameter form of echo instead of string concatenation: this saves the concatenation step:
      // This is fast echo 'Hello', ' world', "\n"; // This is slower echo 'Hello'.' world'."\n";

      Intruded narnia level 2

      Classé dans : Computer security — Mots-clefs :, , — admin @ 13 h 02 min

      The source

      #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(){  int (*ret)();  if((ret=getenv("EGG"))==NULL){  printf("Give me something to execute at the env-variable EGG\n");  exit(1);  }  printf("Trying to execute EGG!\n");  seteuid(1003);  ret();  return 0; }

      Simple, is it? Just put some the address of some executable code in the env var EGG. No… not that simple. The code must be there too.

      Intruded narnia level 1

      Classé dans : Computer security — Mots-clefs :, , — admin @ 12 h 55 min

      This is the source:

      #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(){  long val=0x41414141;  char buf[20];  printf("Correct val's value from 0x41414141 -&gt; 0xdeadbeef!\n");  printf("Here is your chance: ");  scanf("%24s",&amp;buf);  printf("buf: %s\n",buf);  printf("val: 0x%08x\n",val);  if(val==0xdeadbeef){  seteuid(1002);  system("/bin/sh");  } else {  printf("WAY OFF!!!!\n");  exit(1);  }  return 0; }

      So, what’s the point? Overwrite the value of the variable val. Ok. This seems pretty easy: there are two variables used in the program. The compiler will place them on the stack, one after another. Writing in buf, past its length, will naturally override val. This is it! The proof by the example: run the program /wargame/level1 and type 000000000000000000001234. Notice that the value of val (0×41414141) has changed to 0×34333231.

      Ask me why I choose this string. Because buf is 20 bytes long. These are the first 20 zeros of the string. And val is a long, which is 4 bytes. What we have to do is then find the 4 characters that will turn 0×41414141 into 0xdeadbeef.

      The tricky part is how to do that. 0xde, 0xad and so on are not always available on keyboards (at least, my French one). I then wrote and compiled a little program that display these characters and copied/pasted them. Here it is:

      #include &lt;stdio.h&gt; int main (int argc, char *argv[]) { unsigned long l=0xdeadbeef; char *p=(char*)&amp;l; int i; printf("aaaaaaaaaaaaaaaaaaaa"); for (i=0; i &lt; 4; i++)  printf("%c", p[i]); return 0; }

      Some explanations: l is a long with the hex values of the chars I want to display. I need a pointer to a char, p, to iterate throw the bytes. It initially points to l. This why l needs to be casted to a (char *). Because I’m lazy, the program prints 20 a before the 0xdeadbeef characters.

      I ran it, copied/pasted and got suid’ed. I cat’ed /home/level2/.passwd and logged in as level2. :-)

      Programming security

      Classé dans : Computer security — Mots-clefs :, , — admin @ 11 h 44 min

      I’m in. Something I neglected the past years: security in programs. I mean, the kind of security holes one may find deeply buried in the code. Because I’m no more in compiled languages since a bunch of years now, I didn’t really paid attention to these points. Generally, the virtual machines my programs run in take care of these points.

      So, I asked one of my colleagues who works at the Security here to point me to some exercises. He gave me this link: www.intruded.net. I went there and began the wargames.

      The principle is quite simple: you run a program located at /wargame and it displays what has to be done to crack it. The source code is available. All you have to do is read it, find the hole and dive into it.

      Here’s my blog!

      Classé dans : Non classé — admin @ 11 h 21 min

      This is my blog. Finally, I did it!

      Here you will find my thoughts. They will be mainly computer oriented for this is my job and my every day life, after all.

      Let’s go to the first article!

      Propulsé par WordPress