Tuesday, July 11, 2017

PEP20 - The Zen of Python decorators

Idea:
The Zen of Python principles as Python decorators:
@beautiful_is_better_than_ugly
@explicit_is_better_than_implicit
@simple_is_better_than_complex
@complex_is_better_than_complicated
@flat_is_better_than_nested
@sparse_is_better_than_dense
@readability_counts
@special_cases_arent_special_enough_to_break_the_rules
@although_practicality_beats_purity
@errors_should_never_pass_silently
@unless_explicitly_silenced
@in_the_face_of_ambiguity_refuse_the_temptation_to_guess
@there_should_be_one_and_preferably_only_one_obvious_way_to_do_it
@although_that_way_may_not_be_obvious_at_first_unless_youre_dutch
@now_is_better_than_never
@although_never_is_often_better_than_right_now
@if_the_implementation_is_hard_to_explain_its_a_bad_idea
@if_the_implementation_is_easy_to_explain_it_may_be_a_good_idea
@namespaces_are_one_honking_great_idea_lets_do_more_of_those
def func():
    """Idiomatic function"""
Each decorator could act as code analyser.

Thursday, May 25, 2017

SNMP walk in pure Python

Some time ago I've added one more protocol to my github repo. This time SNMP.
I created tool similar to snmpwalk in pure Python. The most difficult part was to implement an ASN.1 parser. Current version supports only SNMP versions 1 and 2.
https://github.com/delimitry/networks/blob/master/networks/snmp.py

Friday, March 17, 2017

VolgaCTF 2017 Teaser - Octaves & Notes writeup

Eve intercepted this midi-file. She only knows that notes must be in 1st and 2nd octaves. Can you help her?

Stegano & Crypto. Hmmm...

Let's open this midi file in audio editor:


I've noticed that only ABCDE and F notes are present (no G note). Thus, it is possible to understood the relationship with hex.

If write out the full melody in octave-note format, we will have the next result:
2D, 1A, 2D, 1B, 2C, 1A, 2D, 1F, ...

Then I've noticed that 0x2d in ASCII is "-" (dash), 0x2c is "," or some sort of delimiter. And the other 4 notes (all in first octave) are non-printable in ASCII.
Often non-printable characters are replaced with a dot in the output.
So using the next Python script, I've got a flag encoded in Morse code:

import string

notes = [0x2D, 0x1A, 0x2D, 0x1B, 0x2C, 0x1A, 0x2D, 0x1F, 0x1E, 0x2C, 0x1B, 0x2D, 0x2C, 0x1F, 0x1E, 0x1A, 0x2C, 0x1B, 0x1F, 0x1E, 0x2C, 0x1B, 0x1A, 0x2C, 0x2D, 0x1B, 0x2D, 0x1A, 0x2C, 0x2D, 0x2D, 0x2C, 0x2D, 0x2D, 0x2D, 0x2C, 0x1B, 0x2D, 0x1B, 0x2C, 0x1A, 0x1B, 0x1F, 0x2C, 0x1E, 0x2C, 0x2D, 0x2D, 0x2D, 0x2C, 0x2D, 0x1B, 0x2C, 0x1F, 0x2C, 0x1A, 0x2D, 0x1B, 0x1A, 0x2C, 0x2D, 0x2D, 0x2D, 0x2C, 0x1A, 0x1F, 0x1E, 0x2D, 0x2C, 0x1E]
out = ''
for n in notes:
    out += chr(n) if chr(n) in string.printable else '.'

print(out.replace(',', ' '))

-.-. .-.. .- ... ... .. -.-. -- --- .-. ... . --- -. . .-.. --- ...- .

And the flag is:

CLASSICMORSEONELOVE

PS: WTF! Where is hint about non-standard flag format? :(