Wednesday, August 28, 2013

Cryptanalysis, Kernel Dev, gtk gui, hardware interfacing

For a while I owned the domain It's gone now, years ago lost to a Chinese domain squatter. Mostly the domain was a place for various experiments with dynamic code (cgi/perl at the time) and a good place to have my own shell account hosting service (eggdrops and honeypots). But I did have some content; a few tutorials about things such as cryptanalysis, gtk gui development, hardware interfacing, and linux kernel module writing. All the hard core geekout topics of the time.

Thanks to a friend buying me a IDE->USB adapter cable I've been inspired to resurrect some of the old drives sitting in the drawers in my home office. On one of them was some of the code I hard written and open sourced at the time. Naturally, the only responsible thing to do is dump it on github. Maybe somebody will enjoy messing around with these concepts as much as I did. I'm not a huge fan of the GPL license, but I'm not going to go through the trouble to relabel all of this. None of it is really usable as a basis for derived works anyway, just snippets.

Here's a picture of the computer that most of it was written on. My trusty 266mhz laptop with 1990s cool geek stickers.

Here's what's in there:

Example code for how to overload operators as member functions and as non member functions.

A simple example Linux Kernel module I threw together to learn and teach Linux 2.4 Kernel module writing.

Replicates the logic of, then brute forces a solution to a simple logic game.

An example of creating a gtk instance. (If you need a simple dialog for a script use gdialog or dialog instead of writing your own instances.)

An example of creating and using Binary Search Trees.

GTK c code program shell for system control using a remote control such as the ATI all in wonder.

Reads various data from the /proc filesystem in linux.  Handy ui and file rw snippets.
Regex snippet to retrieve IPs from a log file.
Perl code to break the list of IPs generated above into their octets.  Handy for use with the unix commands sort and uniq.
A line of perl code to rename a bunch of mp3 files using their modification time.This is handy for organizing streamed audio that overlaps.
Bash script snippet to do an operation on a whole directory of files.

Short Code to output contents your program's memory space, unformatted. (This program is just a few lines to show what can be accessed. If you need to analyze a program's memory space use gdb instead.)

Shellcode to print a phrase to the screen. Good shellcode exercise.

An example of an overflow exploit.

Code written for information warfare games at Norwich University

C++ code to perform small rsa encryption.  Nice example of how to use C++ unions.
Perl Snippet to perform an affine cipher on a file of text.
Complimentary program to to crack affine ciphers.
Perl Snippet to perform block rotation ciphers on a file of text.
Complimentary program to to crack block rotation ciphers.
Perl Snippet to perform columnar transposition ciphers.
Perl Snippet to count letter frequencies in a text file.

Wednesday, August 21, 2013

Half a war story

While gathering some old files for my wife's computer I ran across a narrative that I started writing in Iraq as a Marine advising the Iraqi Army for a year. On the same hard drive were some pictures from the events. I'll never finish writing this, but might as well post it anyway. Towards the end of the story it just devolves into notes about more real life events I had meant to incorporate into this story but never finished. Names are changed and some faces are blurred. Some of these guys take heat for working with US forces in Iraq and I wouldn't want to put anybody in danger, even now years later.
“Do you believe this story?”
Major Ahmed of the Iraqi Army and I stood looking at Adam's tree at the juncture of the Tigris and Euphrates Rivers. I confirmed with a simple yes.
“If you believe this story, then I can not talk to you about religion.”
Areed Ammar piped in with “yes, yes, so everybody can get along”.
“That is correct, without religion is when everybody can get along, comrade.”
I shrugged it off as a few other Marines continued to pose for pictures in what was rumored to once be the garden of eden. A stone monument below the tree was inscribed:
Adam's Tree
In this blessed area where Tigris and Euphrates meet atree was honoured by the visit of our master ibrahim al khaleel peace be upon him in 2000p.c he praged and said here a tree will grow which is similar to our father adams tree peace be upon him in Adans paradise

As we walked by the nearby shoreline of the Tigris river, we were invited to stay and have breakfast with the Iraqi Army leadership. Major Ahmed had a closely guarded and very intelligent personality; an intellectual elite, certain that his ideas of communism were the key to saving the world. His offers of friendship were few as he insisted in distancing himself from most everyone else. I had enjoyed his company previously and took the offer. We sat down in the shack that, until yesterday, had belonged to the proprietors of the small hotel next to Adam's Tree. The rest of the team moved on, content with their brief sight seeing tour.
“Lieutenant, come, have some dog.”
I looked skeptically at the small chunks of burnt meat on the plate and tasted them. Everyone laughed. Another test passed; this type of prodding was constant during my time in Iraq, even when involving misuse of explosives and weapons.
“Don't worry Lieutenant, it's not dog. It's sheep heart.”
“It tastes better now.” More laughing.
The discussion continued on in Arabic. The few brief sentences in English meant to make me feel comfortable during my breakfast now gone. I did my best to keep up with the discussion. I've been in Iraq for 16 months now and have learned a fair bit of the language, but it's not natural to me and takes a lot of mental work to keep up. After struggling through several minutes of chewing heart and discerning what they were talking about I attempted to join in. After fumbling through a few more minutes with my broken Arabic, Lieutenant Reead switched the conversation back to English to make his proposition clear.
“I would like to go in a boat.”
“Let's go.”
“I have been looking for somebody who is brave enough to get in a boat.”
“Can you swim?”
Puffing out his chest “of course I can swim!”
Major Ahmed sheepishly admitted to not being able to swim, a rare confession from a male raised in a culture and profession that places a high priority on courage. I chalked Major Ahmed's ability to self deprecate up to the intellectual ideals that he holds.
“But I will go too.”
Areed Ammar “I will go.”
Lieutenant Slehah “I want to go.”
Lieutenant Reead glanced around the room, mocking confusion. “I asked this same question yesterday and none of you wanted to go!”
“So let's go.”
“After breakfast.”
Major Ahmed pointed to a picture on the wall, mentioning that it was Abu Reisha. I intoned, “a great man; he saved many lives. Him and that American Captain did Iraq a great service.”
“Yes, he did. He had great ideas. But where did the money come from?”
I replied, “the Captain had petitioned for it.”
“A hah!” as though he had caught me in a contradiction. “You are the first American to admit that it was American money.” Well of course it was American Money. We've spent millions of dollars gaining the support of local sheiks in fighting the Iraqi Insurgency. I myself had bartered away hundreds of thousands of dollars in Nasser Wa Salam, gaining the support of the locals and compensating the temporary militia that we used to keep the insurgency or Islamists from bullying civilians. It worked fantastically. It was cheaper than buying bombs, bullets, and getting hit by IEDs, and was infinitely cheaper than sacrificing the lives of Marines. I retorted “who has denied that it was American money?” Major Ahmed waved his arms “everybody.” I took on an air of mock superiority, sitting up straight chest out and confident that Major Ahmed would not be able to answer my next question. “Name one.” “What?” “Name one person who denies that Abu Reisha and the awakening counsel was helped by American money. Anybody.” Unable to answer, “have some more breakfast.” I went over the consequences of calling out Major Ahmed's falsification in my head, then decided the outcome would be impossible to predict and went back to eating my heart and what looked and tasted to be a jalapeƱo pepper. It seemed for the moment as if our tenuous friendship had still survived the turbulence of our infrequent disagreements. Living in such close proximity demands honesty. Minor perceived betrayals of trust here and there could easily escalate into betrayals of my life or the lives of the few Marines here. For the thousands of Iraqi Soldiers and hundreds of thousands of Iraqi citizens around us, there were only 15 US Marines and two Sailors: one Anglico and one Corpsman. It was always like walking a tightrope and there were grim precedents for the price of failing to balance. Our breakfast was among the shattered wrecks of modern British and Iraqi armoured vehicles destroyed during the recent fights over the control of Basrah.

We left the confines of the shack and started towards the river. An old man overheard the Iraqi Officers and jumped into the conversation, at once gaining everyones intention. He formed us into a circle, waving his arms and laughing; his right hand missing his thumb and formed into a shiny ball of scar tissue. I focused on trying to translate his story in my head. He spoke about an Iraqi Army Officer who had once asked to borrow his boat in 1991. That Officer had the same idea that we had. Stuck here on post for days, with nothing going on in this small city, he had simply gotten bored. Paddling out into the middle of the river, his attempt to turn back around to come back to shore had turned into catastrophe as he panicked and flipped the boat. The old man, then much younger, responded to his cries of “Help, I can't swim.” and saved his life. Everyone laughed and thanked the old man for his warning as we continued towards the shore, all confident that we could swim; except for one. The old man yelled after us, holding up his thumb, “deerbalik!” be careful, “I'm not as quick as I once was in the water”. He retreated back to the shade of his tree, easing back down to the ground with a pained pause of his raspy laughter.

Down on the shore Lieutenant Reead waved one of the small river boats over with an empty hand. I confirmed in my mind that I would at once protest if he had signaled with a weapon. I've made it a point to not tolerate bullying of the populace, we need more friends not more adversaries. The young boy threw his whole body weight into moving the small paddle, his feet picking up off the deck, and steered his boat towards the shore. He was excited about the opportunity to converse with us. American presence was extremely rare in this part of Iraq, some of his enthusiasm was probably curiosity. Lieutenant Reead hopped in and waved me in behind him. I paused as I caught the words lah! and ethnien out of the boy's hurried Arabic (No! Two). Areef Mohanned, behind me explained in English that the boy was told by his father that his boat could only hold two people and that more would sink the small boat. I sheepishly complied and took my place higher on the shore with the rest of the officers to watch the spectacle. The boy put all of his 50 pounds of weight into pushing the boat away from shore and they were off for a short joy ride, Lieutenant Reead unable to contain his smile. The other officers snapped some pictures, and laughed at things in Arabic that I couldn't understand. A larger boat, commanded by two similarly small boys, abandoned their fish nets to come watch the show. Upon returning to shore, Lieutenant Reead called the larger boat over. This time there was enough room for me and I rushed to take my seat, my enthusiasm threatening to make the small boat tip and eliciting halted cries of terror from our tiny Admiral. 

We cruised into the Tigris with our child powered boat switching our discussion between Arabic and English as we each blamed each other for rocking the boat. I gave a brief history lesson about amphibious landings in World War II while trying to explain that because I was a US Marine it meant I could swim very well. Marine is a synonym for water, we're an amphibious fighting force. The language barrier was too much, it was lost. As we floated in view of the local civilian population yells of “Iraqi Amreeki” spread through the gathering crowd. Lieutenant Reead translated for me, “Iraqi and American are together in the River.” As we approached shore to land we both drew our pistols and held them in the air, everyone laughing at jokes about the new Iraqi Navy and their advisor. 

Lieutenant Reead and I had shown it was possible, now Major Ahmed wanted his turn. He pointed to a much larger boat that had been working it's nets up the river. Lieutenant Reead yelled to them and they protested. He drew his pistol and waved them over with it. Acting on my previously decided course of action, I went to his side and told him, loud enough so that only he could hear me, to put his pistol away. “We don't need to scare them into helping us.” “Forget about it, they are coming now.” Major Ahmed grinned and turned away from me. At least the weapon was holstered.

Major Ahmed's increased protests culminating in outright anger.
Lieutenant Reead rocking the Major's boat.
The tired boys, working for their father who was at home.
The Iranian Bridge from the 1980s war. The manufactured bridge next to it.
The Dog walking out the Iranian Bridge and then swimming across where it had been blown. The Dog sniffing our Anglico team.
The Fire I saw on patrol and then predicted that an aircraft was going to point it out for me on the radio. Thanks for nothing.

The first vehicle getting stuck. Driving perfectly fine on solid dirt and then singing to the axle because a water pipe had burst and turned the dirt under the surface to a “quagmire?”
Us using the winch to attempt to get it out. Forgetting about the blocks. Sowersby getting out of the gun in case it rolled. Moore driving. Me taking off my flak jacket to get to the axle to tie on the cable. Ssgt forgetting to take off the air brake and then being able to laugh about it.
Division driving up. The Colonel cursing Mraps. Sowersby cursing Mraps. Doc and I defending Mraps. Ssgt Loving Mraps.
Fixing the pipe with MRE Bag and zip ties. Cutting my hand. Doc cleaning me off with the water he was drinking, using the whole bottle.

The second vehicle getting stuck. Pulling up beside. Stapler not opening door, and attempting to gun it. Me stopping him, going to look. Seeing the axles had dug into the asphalt. Carney not wanting to leave the turret. Ssgt driving our 6x6 onto the same weak asphalt. Seeing the results on foot. Deciding the winch is too weak. Backing in. The Major protesting. Lt Arendt (tony) suggesting to use the chain hooked to the end of the tow bar. Me telling stapler how to throttle it. The vehicle pulling right through the asphalt and out onto stable ground again. Me making them put up their own tow bar after Carney and I had taken it down.

Start of the operation.
Driving in. Not liking the streets that the IA had gone down with their humvees. Anglico hopping from rooftop to rooftop. The unbearable stench of the streets from the open sewage. The flies in the market place. The lady in black with the food dropping onto the ground. The man with the horse tail waving over his meat, only to stop and have the flies lift off of it again.

What is the significance of the three stars on the river front terrace? Describe the river front terrace. Describe the ancient brick buildings, the mortar missing from between the bricks. The intermittent collapse of portion sof the wall, the modern patches, the face of Hussein Ali and Sader posted on the walls.

The straggering amount of litter on the shores of the river.
Doc explaining that the shores are the same in the phillipines.
The Motor boats buzzing down the river.
The Stun Grenade for fish.
The Fishing Nets running away down the river.
The small garden that somebody came to water. They had moved my trash bag sitting on bare dirt to water it, but had not thought to remove several pieces of litter from their small garden. Strange.

Falling asleep on top of the vehicle listening to my Ipod.
The Police shooting at people trying to cross the bridge.
The Men in the street working on an engine with rock tools covered in oil.

Walking down the street with the coffee maker, looking for a plik (plug). Finding one, but having to endure kabob in order to make coffee. The man with his concerns that the militia will return as soon as we leave. Reassurances that the militia will not return because 14th division will hold this area. Talk of the militia's checkpoints and their murdering of a woman for not wearing a head scarf, their continued murders of her mother, and a teenage boy apparently in love with her, that had ran to her defense. Orange pickles strong with vinegar. Strong green leaves “green paper” with a minty taste.

The boys playing soccer. Walking way way too close.
Me telling the story about the steak knife.
The game of spades. Doc sunglasses and mp3 player. Ssgt predicting hands with surprising accuracy. Sowersby with the ice and his head hankerchief.

Sowersby insisting on sleeping on the ground.

The Iraqi's posted in full gear in direct sunlight every few meters along the river as a show for the General Tareeq.

My eyes opened, the brightness of the sunlight pouring in through the armored vehicle's five inch thick windows causing me to squint. I looked out across the Tigris River and noticed a middle aged man collecting a cast net. He was teetering on the edge of the remains of an Iranian military bridge, placed here several decades ago as waves of Iranian soldiers invaded this part of Iraq. The fighting in this part of the country had been especially bloody as both sides sent hundreds of thousands of brainwashed or reluctant martyrs to clash in the desert and on the streets of Basra and our current location Al Gamora. The metal bridge had subsequently been partially destroyed and now was a rusted green floating mass of steel that extended three quarters of the way across the river, it's sunken pieces and various cables keeping it steady in the lazily flowing Tigris River.
I watched intently, making sure not to lose sight of him so that I'd see his next cast. A short Filipino lady on the Gotshok Marine on Camp Lejeune had taught me on a humid August day a few years ago. Her stature and mastery of an extremely large net was impressive. She had patiently taken the time to instruct me on the difficult art and I immediately purchased my own cast net upon leaving that day. Throughout the next two years I had used my small cast net to catch shrimp and bait fish out of the coastal North Carolina waters. The man standing on the floating steel bridge had a cast net every bit as large as the Filipino lady and was wielding it with every bit as much skill and great success. After watching a few casts, I eased out of the truck and walked down to the bridge, joining him on the shattered steel that marked where the bridge ended and descended into the shallow edge of the river. He acknowledged me with a courteous wave and we exchanged the mandatory courtesies in Arabic.
“A salam alaykoom” Peace be upon you.
“Wa alaykoom a salam” And upon you also.
“Sabaa elkgerr” Good morning.
“Sabaa hinoor” Good to you.
At my request, he completed his preparations then turned and threw the net again into the water, it's edges forming a perfect circle in the air before it slapped down into the water with a satisfying even splash. He waited a moment and then drew the net back. Water dripped off the coiled rope in his hand and on to his white canvas pants. The net slowly became visible and sagged under the weight of several hearty fish, which he shook out onto a level part of the bridge and then placed into an insulated shopping bag. We made eye contact and he saw my eagerness to give it a try also. I feigned ignorance out of courtesy as, for my education, he made exaggerated movements and went through the tedious and complicated steps of preparing and gathering the large net into his hands, his mouth, and around his body for throwing. I laughed as, his mouth and arms full of net, he shook his body, mumbled, and raised his eyebrows in emphasis that this was the final position from which he was to throw the net. His final form, wrapped up in the net, reminded me of what the fish looked like before he dropped them onto the bridge. I nodded in acknowledgment and watched as he tossed it. The net hit the water at a crooked angle and failed to open. I chalked his mistake up to stage fright, or that lack of grace we all experience when we know we are being watched intently. Not wanting to dissuade him, and paying honor to his Arabic male pride, I smiled pleasantly and requested that he show me how.

He helped me cast the net several times, preparing it for me on my body.
Two Iraqi Police Officers came up and used a bunch of words I didn't understand and stood way too close.
I finally managed to get the net out on my own and caught three fish.
A gathering of children had accumulated.
Rico walked up behind me.
After my victory I went to sit with Rico on the edge of the bridge with my feet in the water.
Corporal joined us.
We talked about swimming and corporal admitted to not being able to.
He was growing out his facial hair for an operation the next day.
The children showed up and started to swim.
A teenager showed up in his underwear with soap and the Iraqi loofa and borrowed my knife to cut open a water bottle to use to rinse himself off. He too admitted to not being able to swim.
Rico, Corporal, and I discussed the eel in the pile of discarded fish to my left.
Rico claimed that the children said it was used to treat asthma. It was left to dry in the sun and then ground into a powder to mix with honey.

The corner shop where we made coffee every morning with their generator. The generator bogging down with the strain of the coffee maker. Rico demanding that I eat kabob on that first morning, the kabob being raw. The orange Iraqi pickles.

Saturday, August 10, 2013

Snowden Leak Link List

Regardless of your feelings on the issue, Snowden's leak was probably the most important thing to happen in the last ten years for the fields of National Security and Information Security. There are lots of changes in motion and it's unclear how things will settle, but here are some important facets of the topic from both sides that may give clues.

He did break the law. No matter how things fall out, despite the merit and significance of his claims, no laws exist to protect him.
There is public cause to think that oversight was broken or at least inefficient and error prone.

The information he has released has caused over 19 activist organizations to file lawsuits against the government, including the EFF.

The leaks are triggering government reforms and more ovesight.

Secure email providers are being targeted or are pre-emptively closing their services rather than be seen as complicit in government surveillance.
Phil Zimmerman, the creator of PGP owned Silent Circle.

This makes related privacy issues much more complicated such as the government attacks against the TOR network.
Side note: Tor was created by the government to protect anonymity.