Nitraqu의 블로그

nitraqu.egloos.com

포토로그



헷갈리는 파이썬 코드 문법 들 정리 Python - Basic







1. for loop list 만들기

[bean for bean in beans if bean.type == 'coffee']



2. yeild / next 

def permutations_dup(array, r):
for i in range(len(array)):
if r == 1:
yield [array[i]]
else:
for next in permutations_dup(array, r-1):
yield [array[i]] + next



Tshark - pcap 파일 처리 관련 옵션 정리 데이터 분석



저장한 패킷 파일들을 일괄로 특정 조건으로 필터링 할 때가 있다.

파이썬으로 굳이 예를 들자면


import os
import subprocess
 
 
input_path = r"input"
file_list = os.listdir(input_path)
output_path = r"output"
 
for each_file in file_list:
input_file = os.path.join(input_path, each_file)
output_file = os.path.join(output_path, each_file)
 
if input_file.endswith(".pcap") is False:
continue
 
command = f'tshark -r "{input_file} -w "{output_file}" -Y "tcp"'
 
subprocess.check_output(command, shell=False)
 
정확한 이유는 모르겠는데...
subprocess 의 인자로 파일 이름을 작은 따옴표로 묶어 주면 오류가 나고  큰 따옴표로 묶어 주면 오류가 나지 않았다.
(Windows) 


리눅스 운영체제 배포판 - Slingshot 프로그래밍 - 그 외

Slingshot은 Kali Linux와 비슷한 침투전문 도구가 설치된 리눅스 기반 운영체제이다. 

SANS 라고 하는 보안 전문 교육 기간에서 배포하는 버전이다.

https://www.sans.org/tools/slingshot/

다음의 도구들이 설치되어 있다고 한다. 

모르는게 태반이군,,,

Tools Included in Slingshot CE (Community Edition)

  • Aircrack-ng
  • Asleap
  • basicblobfinder
  • BeEF
  • Bettercap
  • binwalk
  • Burp Suite
  • checksec.sh
  • chisel
  • CloudMapper
  • Covenant
  • coWPAtty
  • Docker
  • Empire 3 (BC Security fork)
  • Ettercap
  • ExploitDB
  • EyeWitness
  • Flamingo
  • GCPBucketBrute
  • hashcat
  • hping3
  • httpie
  • John the Ripper
  • Kismet
  • Kiterunner
  • Koadic
  • Masscan
  • Metasploit Framework
  • ncat
  • Nikto
  • Nmap
  • OpenVAS
  • Padbuster
  • Powershell Empire
  • ProjectDiscovery tools
  • Recon-ng
  • Responder
  • RITA
  • ScoutSuite
  • Sherlock
  • Social Engineer Toolkit
  • sqlmap
  • tcpdump
  • THC-Hydra
  • Unicornscan
  • Veil Evasion
  • Wapiti
  • WeirdAAL
  • Wireshark
  • WPScan
  • Zed Attack Proxy

[AI] Gym - OpenAI : AttributeError: 'ImageData' object has no attribute 'data' 해결 데이터 분석

1. 상황:  gym + jupyter + 원격 서버 접속
- 문제점 :  env.render ( ) 호출 시, 화면이 server 에 뜬다. 

2. 해결책: 
- 검색하다 보면 다양한 해결책이 검색됨을 알 수 있다.
- gif 나 ffmpeg 와 같은 방식으로 영상을 만들고 그걸 브라우저에서 여는 방법도 있고 
- X11 을 서버/클라이언트 환경을 구축해서.. 브라우저에서 보는 방법도 있는 것 같았다. 

우선: gym-notebook-wrapper 를 이용한 예제를 수행해 보기로 하였다. 
- 위로 치면 영상이나 gif 를 만들어서 저장하고, 브라우저에서 보는 형태이다. 

https://pypi.org/project/gym-notebook-wrapper/

3. 실행 

sudo apt install xvfb
sudo apt install python3-opengl 
sudo apt install ffmpeg # 영상을 이용하는 예제에서 필요. 

- gym-notebook-wrapper 설치 
$ pip install gym-notebook-wrapper

예제 코드 1을 실행해 보았다.

import gnwrapper
import gym
 
env = gnwrapper.Animation(gym.make('CartPole-v1'))
 
obs = env.reset()
 
for _ in range(1000):
next_obs, reward, done, info = env.step(env.action_space.sample())
env.render()
 
obs = next_obs
if done:
obs = env.reset()

하지만 늘 그렇지만... 제대로 돌아가지 않는다. 

오류 내용은 
- AttributeError: 'ImageData' object has no attribute 'data'
pyglet 에서 문제가 있다.
- 이런 저런 글들을 보니 gym 에서 pyglet 이 이슈가 많아서 향후 버전에서는 안 쓸거다.. 라는 이야기도 있다. 
- 그래도 나는 지금 써야 겠으니 ㅠㅠ

이어지는 내용

[AI] Gym - OpenAI UI - Render ( ) 관련 프로그래밍 - 그 외

openai 관련 이것 저것 테스트 중인데, 

예제들이 하나 같이 동작하지 않는다. 

(물론 대부분의 오류는 마이너하긴 하다. 함수 리턴값이 바뀌었다던가...) 

제일 많은 오류는 

env.step( ) 의 리턴값이 4개였다가 5개로 바뀐 점이라던가..

env.render( ) 의 'mode' 인자가 사라졌다던가...  등이다.

gym.make 를 할 때, render_mode='human'을 해야 UI가 생성되는 것을 확인하였다. 



1. 버전 확인 

- pip로 gym 최신 버전 설치
- ubuntu 22.04 최신 버전 유지. 

>>> gym.__version__
'0.26.1'
>>> exit()
nitraqu@nitraqu-7c79:~$ uname -ar
Linux nitraqu-7c79 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

2. 코드  

import gym
print (gym.__version__)

import gym
print (gym.__version__)
 
env = gym.make('CartPole-v1', render_mode='human')
for i_episode in range(20):
# 새로운 에피소드(initial environment)를 불러온다(reset)
observation = env.reset()
for t in range(100):
env.render()
# 행동(action)을 취하기 이전에 환경에 대해 얻은 관찰값(observation)
print('observation before action:')
print(observation)
action = env.action_space.sample()
observation, reward, done, truncated, info = env.step(action)
# 행동(action)을 취한 이후에 환경에 대해 얻은 관찰값(observation)
print('observation after action:')
print(observation)
 
if done:
print("Episode finished after {} timesteps".format(t+1))
break

1 2 3 4 5 6 7 8 9 10 다음