Introduction to Information Security Python. Python motivation Python is to a Hacker what Matlab is to an engineer Lots of built-in modules Lots of 3.

Slides:



Advertisements
Similar presentations
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Advertisements

For loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas.
Chapter Modules CSC1310 Fall Modules Modules Modules are the highest level program organization unit, usually correspond to source files and.
Python for Science Shane Grigsby. What is python? Why python? Interpreted, object oriented language Free and open source Focus is on readability Fast.
Introduction to Python Week 15. Try It Out! Download Python from Any version will do for this class – By and large they are all mutually.
Bruce Beckles University of Cambridge Computing Service
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
What is a scripting language? What is Python?
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
AWK: The Duct Tape of Computer Science Research Tim Sherwood UC San Diego.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
CSC 9010: Natural Language Processing
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
1 CSC 221: Introduction to Programming Fall 2012 course overview  What did you set out to learn?  What did you actually learn?  Where do you go from.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
Introduction to Python John Reiser May 5 th, 2010.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.
H3D API Training  Part 3.1: Python – Quick overview.
Introduction to Python September 26, /10/ Bioinformatics Languages Low-level, compiled languages: C, C++, Java… Pros: performance Cons:
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
>>> # Fibonacci series:... # the sum of two elements defines the next... a, b = 0, 1 >>> while b < 10:... print b... a, b = b, a+b WHILE.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Documentation / References Python Full Documentation – Python Quick Reference –
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
GE3M25: Computer Programming for Biologists Python, Class 5
Python’s Standard Library Part I Joe Houpert CS265.
Python  Monty or Snake?. Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.
A Tutorial on the Python Programming Language. Overview Running Python and Output Data Types Input and File I/O Control Flow Functions.
Scope, Aliasing, Tuples & Mutability Intro2CS – week 4a 1.
Lecture 4 Python Basics Part 3.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
LECTURE 20 Optimizing Python. THE NEED FOR SPEED By now, hopefully I’ve shown that Python is an extremely versatile language that supports quick and easy.
12. MODULES Rocky K. C. Chang November 6, 2015 (Based on from Charles Dierbach. Introduction to Computer Science Using Python and William F. Punch and.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
Department of Computer Engineering
C-Shell with Functions
CSC 352– Unix Programming, Spring 2016, Final Exam Guide
Lesson 10: Dictionaries Topic: Introduction to Programming, Zybook Ch 9, P4E Ch 9. Slides on website.
Lecture 2 Python Basics.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
CSC 352– Unix Programming, Fall 2012
CSC 108H: Introduction to Computer Programming
Functions CIS 40 – Introduction to Programming in Python
PH2150 Scientific Computing Skills
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
CSC 352– Unix Programming, Fall, 2011
Lists Like tuples, but mutable. Formed with brackets: Assignment: >>> a = [1,2,3] Or with a constructor function: a = list(some_other_container) Subscription.
Presentation transcript:

Introduction to Information Security Python

Python motivation Python is to a Hacker what Matlab is to an engineer Lots of built-in modules Lots of 3 rd party modules IDA-Python! Very popular language, very well supported Has implementation in every OS. Human readible Its free

Python Diff In this quick overview of python: We will note the major differences between python and other familiar languages. And talk of some useful tools

White spaces if you can read this: it must be python! -Python hierarchy is defined by whitespaces -Indentation has to be the same (3 spaces != 1 tab) for every nest within the chain.

Hello, World Example #1: #!/usr/bin/python print “Hello, World!” Example #2: #!/usr/bin/python def main(): print “Hello, World!” if __name__ == ‘__main__’: main()

Datatype behavior Datatypes behave differently in python: A = 5 A = 6 Now A is a different variable! Therefore if use: A = A + 5 Now A is a new variable containing the result!

Basic functions Using the interpreter allows us to view two basic things: dir(object) – shows us the structure of the object help(object) – shows help created by the developer of the object

Strings Many builtin string machnisms. A = “” Len(“123”) == 3 A[0] = “a” – not possible, strings are immutable. A.find(“asd”) returns the location of asd in A A.split()/A.join() A.lower() Replace() – returns a new string with data Uses regular indexing.

Lists and Tuples A = (1, 2, 3) A is of fixed length and is immutable. A = [ 1, 2, 3] A is mutable, and the length can be changed by using append: A.append(4) print A results in: [1, 2, 3, 4] A is not a new variable.

Spans Spans makes things very comfortable: A = “asd” A[0:] == “asd” A[1:] == “sd” A[0:-1] == “as” A[0:1] == “a” A[0:-2] == “a” A[:2] == “as” A[1:2] == “s” Works on tuples, and lists!!

dict()s >>> b = dict() >>> b["hello"] = "world" >>> b {'hello': 'world'} [Demo dicts]

Mutable vs Immutable Mutable A = [1,2,3,4] B = A A.append(5) print B [1,2,3,4,5] Immutable A = “foo” B = A A = A + “bar” print B “foo”

Format conversion print “%d %s 0x%08X” % (0xdeadbeef, “ == “ 0xdeadbeef) 5 / 3 == 1 5 / 3.0 == … int(5/3.0) == 1 str(1) == “1” ord(“0”) == 0x30 chr(0x30) == “c”

File handling Reading from a file: f = file(“c:\\filename”) # file(“/tmp/filename”) for linux buf = f.read() # buf now contains entire file. lines = buf.split(“\r\n”) # lines contains a list with all lines excluding the “\r\n” f.close() Writing to a file: file(“filename”, “wb”).write(data) # using returning # object to write the data # if reference is lost file is automatically closed.

Functions Functions can return arbitrary objects such as: o strings o Tuples! (very common) o int o Etc. global_var = 6 def funcname(arg1, arg2): local_var = 5 return (var1, var2) Updating global variables needs special handling: globvar = 0 def set_globvar_to_one(): global globvar # Needed to modify globvar globvar = 1

if,else if 1: print “always here” else: print “never here” switch case alternative: if key = “x”: exit() elif key = “z”: suspend() else: print “default”

for, while for (i=1; i < 10; i++) alternative: for i in range(1,10): # help(range) for more options print A[i] while 1: cmd = get_next_cmd() if cmd == “stop”: break elif cmd == “dothis”: dothis() continue print “always here ?!?”

Import,reload import sys – a way to import libraries Access to variables is now through the namespace sys.argv[1] Alternatively: from sys import * - Now we can access: argv[1] # direct access. If library was modified after import we can use reload

Useful functions Complex binary operations: o import struct o struct.pack(“L”, 0xdeadbeef) – result contains DEADBEEF in little endian (EFBEADDE) (0xdeadbeef is treated as unsigned long) o (port) = struct.unpack(“>H”) - read unsigned short from a string represented as bigendian OS operations: o import os o os.rename(old_name, new_name) o os.system(“run command”)

3 rd party modules You can install many modules by using pypi On UNIX installing modules is very easy: o sudo pip install [modulename] Also available easy_install Useful imports: scapy (packet manipulation lib works with libpcap), numpy/scipy, pylab, pylib, hashlib, socket, sqllite, gzip, zip, bz2, html, json, wave/audioop (audio operations), PIL (image processing), wave, pygame Google: [something I need] python

ipython Extended interpreter capabilities Acts almost like a shell Adds history Adds file completion by tab. + Many more features.