Ubuntu Server 사용기

Articles 2021/03/19 20:45 용비
리눅스 Desktop으로는 Ubuntu를, Server로는 CentOS를 사용해 왔는데,
RedHat에서 CentOS를 향후에는 자사의 테스트 용도로만 사용한다는 소식이 있네요.

선택의 폭이 좁아져 안타깝지만, Server도 Ubuntu 서버 버전을 설치하여 사용해야 할 듯 합니다.

VirtualBox에 Ubuntu 18.04 LTS 서버를 설치하고,
개발한 어플리케이션을 배포하여 테스트할 환경을 구성하고자 했는데...

CentOS처럼 Ubuntu 서버를 VirtualBox에 설치하고,
Putty나 Solar-Putty와 같은 오픈소스 콘솔을 통해서 서버에 접속하려고 했더니 접속이 안 되어 이상하다 여겼는데...

openssh-server가 default로 설치되어 있지 않네요, Ubuntu 서버에는.

다음 명령어로 openssh-server를 설치해 주어야 VirtualBox Port Forward 기능을 이용하여 Putty로 접속할 수 있습니다.

sudo apt install -y openssh-server

뭔가를 새롭게 알아가는 것은 즐거운 일입니다.
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/881

<02. Resource Injection : 리소스 주입>


발생 원인 : 외부 입력값이 내부 자원에 대한 식별자가 되는 환경에서 입력값에 대한 검증이 없을 경우 발생

영향 : 시스템 내부 자원 접근, 수정, 자원 간의 충돌 발생


Bad Code : Servie No 대한 입력값 검증이 없음

public void createSocket() throws IOException {


   int def = 1000;

   ServerSocket serverSocket;

   Properties props = new Properties();

   String fileName = "file_list";

   FileInputStream in = new FileInputStream(fileName);

   props.load(in);


   //외부 입력 데이터

   String service = props.getProperty("Service No");

   int port = Integer.parseInt(service);


   //외부 입력 데이터로 소켓 생성

   if (port != 0) {

      serverSocket = new ServerSocket(port + 3000);

   }

   else {

      serverSocket = new ServerSocket(def + 3000);

   }

   ......

}


Good Code : 외부 입력값에 대한 기본적인 검증 후, 적절한 값을 할당

public void createSocket() throws IOException {


   int def = 1000;

   ServerSocket serverSocket;

   Properties props = new Properties();

   String fileName = "file_list";

   FileInputStream in = new FileInputStream(fileName);


   //외부 입력 데이터

   String service = "";

   if (in != null && in.available() > 0) {

      props.load(in);

      service = props.getProperty("Service No");

   }


   //외부 입력 데이터 검증

   if ("".equals(service)) {

      service = "1";

   }


   int port = Integer.parseInt(service);

   //외부 입력 데이터에 따른 포트번호 설정

   switch(port) {

      case 1: def + 1; break;

      case 2: def + 2; break;

      case 3: def + 3; break;

      case 4: def + 4; break;

      default: port = def;

   }


   //검증 완료된 포트로 소켓 생성

   serverSocket = new ServerSocket(port);

   ......

}

받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/880

<01. SQL Injection : SQL 주입>


발생 원인 : 외부 입력값이 DB Query 작성에 이용되는 환경에서 입력값을 검증하지 않는 경우에 발생

영향 : 조작된 Query 통해 DB 내용이 노출되거나 변조될 있음

Bad Code : Table Name name 대해 검증하지 않은 코드

Connection con = null;

PreparedStatement stmt = null;


try {

   String tableName = pros.getProperty("jdbc.tableName");

   String name = pros.getProperty("jdbc.name");

   String query = "SELECT * FROM " + tableName + " WHERE Name = " + name;

   stmt = con.prepareStatement(query);

   rs = stmt.executeQuery();

   ........


} catch (SQLException slqe) {}

finally {

   rs.close();

   stmt.close();

   con.close();

}


Good Code : Query문의 구조가 변경되지 않는 PreparedStatement 클래스를 이용하여 쿼리를 수행

Connection con = null;

PreparedStatement stmt = null;


try {

   String tableName = pros.getProperty("jdbc.tableName");

   String name = pros.getProperty("jdbc.name");

   String query = "SELECT * FROM ? WHERE Name = ? ";

   stmt = con.prepareStatement(query);

   stmt.setString(1, tableName);

   stmt.setString(2, name);

   rs = stmt.executeQuery();

   ........


} catch (SQLException slqe) {}

finally {

   rs.close();

   stmt.close();

   con.close();

}


<대표적인 취약점>

Case 1 : 서버에서 다음과 같은 쿼리 실행 코드가 있는 경우 취약점 존재

SELECT * FROM " + tableName + " WHERE name = '" + name + "'"


Case 2 (Blind SQL Injection) : 아래 Normal Query Abnormal Query 실행 결과가 같은 경우 취약점 존재

<Server Query> strSQL = "select user_id, name, user_pwd from member where user_id='"&id&'" and user_pwd='"&password&"'

<Normal Query>http://test.com/member/member_login_check.jsp?user_id=hacker&user_pwd=1234

<Abnormal Query>http://test.com/member/member_login_check.jsp?user_id=hacker&user_pwd=1234' and 1=1--

substr(), ascii() 함수 등을 이용하여 서버의 response , 거짓임을 이용하여 데이터 추출하는 방식


Case 3 : Mass SQL Injection

SQL Injetion 탐지 패턴을 우회하기 위해 CAST 함수 이용하여 쿼리문 인코딩하여 공격


Case 4 : Cookie 이용한 공격

 Query String 대한 길이를 제한하거나 서버에서 PreparedStatement 사용하여 해결

받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/879