ast.literal_eval(node_or_string)은 eval()보다 안전한 방법으로 node 또는 string을 인자로 받아 적절한 strings, bytes, numbers, tuples, lists, dicts, sets, booleans, None값을 return 해 준다.


import ast
ast.literal_eval("{'muffin' : 'lolz', 'foo' : 'kitty'}") # = {'muffin': 'lolz', 'foo': 'kitty'}


1. 일반적인 os.system으로 명령

import os

os.system('ls -l')
간단한 명령을 출력하려면 위와 같이 사용 가능하나 저 결과값을 이용해서 무언가를 하기 위해서는 부적절하다. 명령 실행 결과의 성공 유무를 리턴하기 때문이라고 한다.


2. subprocess로 변수 이용

import subprocess

subprocess.call ('ls -al', shell=True)
call 메서드는 os.system처럼 간단한 명령을 출력할 수 있다. 출력값을 변수에 넣어 사용하기 위해선 check_output을 사용할 수 있다.
import subsubprocess

a = subprocess.check_output('ls', shell=True)
print a
check_output 메소드를 사용하면 결과값을 string으로 리턴하기 때문에 변수에 넣을 수 있다.


ref. http://noplanlife.com/?p=949

php로 웹 개발할때 date함수를 사용하면 아래와 같은 warning이 뜹니다.

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in

이 경고를 해결하기 위한 방법입니다.


1. /etc/php.ini 에서 datatimezone = Asia/Seoul 로 바꿔줍니다. 



2. php 위에 date_default_timezone_set('Asia/Seoul'); 를 추가합니다.

'Language > PHP' 카테고리의 다른 글

IF문에서 신기한것  (0) 2017.12.18
usage:
from pwn import *
context(arch = 'i386', os = 'linux')

r = remote('exploitme.example.com', 31337)
# EXPLOIT CODE GOES HERE
r.send(asm(shellcraft.sh()))
r.interactive()


도큐먼트


 Our documentation is available at pwntools.readthedocs.org 
 To get you started, we've provided some example solutions for past CTF challenges in our write-ups repository. 


설치방법

 $ pip install pwn


ctf할때 유용하게 사용할 수 있는 툴입니다. 
python 2.7버전을 권장합니다.



#-*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import BeautifulSoup, urlparse, os, time, random

def getPeopleLinks(page):
    links = []
    for link in page.findAll('a'):
        url = link.get('href')
        if url:
            if '/profile.php?id=' in url:
                links.append(url)
    return links

def getID(url):
    pUrl = urlparse.urlparse(url)
    return urlparse.parse_qs(pUrl.query)['id'][0]

def view_friend():
    print "[+] 친구목록 탐색중"
    private_page = driver.find_element_by_class_name('fbxWelcomeBoxSmallRow')
    ActionChains(driver).move_to_element(private_page).click().perform()
    friend_page = driver.find_element_by_class_name('_39g5')
    ActionChains(driver).move_to_element(friend_page).click().perform()

def login_web():
    facebook_id = driver.find_element_by_name("email")
    facebook_pw = driver.find_element_by_name("pass")

    facebook_id.clear()

    facebook_pw.clear()

    facebook_id.send_keys("")

    facebook_pw.send_keys("")

    facebook_pw.send_keys(Keys.RETURN)
    print "[+] 로그인 성공! 봇을 시작합니다."

def write_timeline():
    facebook_write = driver.find_element_by_name("xhpc_message")
    facebook_write.clear()
    facebook_write.send_keys("`1234567890~!@#$%^&*()_+|")
    if facebook_write.send_keys(Keys.RETURN) == None:
        print "[+] 글 작성 완료!"

def viewbot(driver):
    visited = {}
    pList = [ ]
    count = 0
#	while True:
    for i in range(10):
#      sleep to make sure everything loads.
#      add random to make us look human.
#time.sleep(random.uniform(3.5,6.9))
        page = BeautifulSoup.BeautifulSoup(driver.page_source)
        people = getPeopleLinks(page)
        if people:
            for person in people:
                ID = getID(person)
                if ID not in visited:
                    pList.append(person)
                    visited[ID] = 1
        if pList: #If there is people to look at, then look at them
            person = pList.pop()
            driver.get(person)
            count += 1

        print "[+]"+driver.title[3:len(driver.title)]+" Visited! \n("\
            +str(count)+"/"+str(len(pList))+") Visited/Queue"
        driver.back()

def Main():
    os.system('clear')
    print """
    =====================**************************======================
    =====================Facebook Friends Search Bot_made by SSo===========
    =====================**************************======================

    """
    web = 'https://facebook.com/login.php'
    global driver
    driver = webdriver.Firefox()
    driver.get(web)
    print "[+] 웹 사이트 접근 성공(" + web + ")"
    assert "Facebook" in driver.title

    login_web()
    driver.implicitly_wait(10)

    view_friend()
    viewbot(driver)



    assert "No results found." not in driver.page_source

    print "[+] 자동탐색기 종료"
    driver.close()

if __name__ == "__main__":
    Main()

'Language > python' 카테고리의 다른 글

python에서 bash 명령  (0) 2017.05.24
[라이브러리] pwntools - CTF toolkit  (0) 2016.08.04
Python String maketrans() Method  (0) 2016.07.19
파이썬으로 웹 브라우저 실행하기  (0) 2016.07.10
정규표현식 (Regular Expression)  (0) 2016.06.13

import webbrowser
url = "http://naver.com"
webbrowser.open(url)

파이썬에 입력을 받는 input이 있습니다.



>>> a = input("input value: ")

input value: 3

>>> a

3


input에 test를 입력하면 변수로 읽습니다.


>>> test = "ABCD"

>>> a = input("input value: ")

input value: test

>>> test

'ABCD'


input은 a를 정수로 받아옵니다.


문자열을 받고 싶으면 raw_input을 사용하면 받을 수 있습니다.


>>> a = raw_input("input value: ")

input value: ABCD

>>> a

'ABCD'

+ Recent posts