이름 "**"은(는) 이 컨텍스트에서 사용할 수 없습니다. 올바른 식은 상수, 상수 식 및 변수(일부 컨텍스트의 경우)입니다. 열 이름은 사용할 수 없습니다.


string을 큰따옴표로 감싸주니 안먹음

'' 로 감싸주어야 함

Posted by Righ
,

modprobe nf_conntrack_ftp ports= 에 포트를 ','로 구분하여 추가한다.


modprobe는 리눅스 커널에 모듈을 적재하는 리눅스 프로그램이다.

Posted by Righ
,

iptables -I chain1 -d 2.2.2.2 -m geoip --src-cc CN -j DROP


iptables v1.4.7: Couldn't load match `geoip':/lib64/xtables/libipt_geoip.so: cannot open shared object file: No such file or directory


=>

wget으로

xtables-addons-2.10.tar

받아와서 configure


configure시 


No package 'xtables' found


만약 iptables를 소스 컴파일 하였다면 설치된 경로를 --with-xtables 옵션에 적어주고 compile 패키지 설치 한 경우에는 iptables-devel을 install 해준다.


=> 계속 make에서 comflict 에러... 에러 확인 해보니 

#warning Kernels below 3.7 not supported.

위와 같은 comment 가 있었다.


작업하던 리눅스의 커널 버전은 2.6.32**** 였으므로 

xtables-addons-1.47.1

로 다시 받아서 compile 후 make


또 에러

too few arguments to function 'ipv6_find_hdr

=>


/usr/src/kernels/`uname -r`/include/linux/autoconf.h

에서

/*#define CONFIG_IP6_NF_IPTABLES_MODULE 1*/

주석처리

다시 compile 후 make
성공!

첫 명령어 다시 시도
iptables -I chain1 -d 2.2.2.2 -m geoip --src-cc CN -j DROP

/usr/share/xt_geoip/LE/CN.iv4: No such file or directory

뻐킹..

cd /설치 경로/xtables-addons-1.47.1/geoip

./xt_geoip_dl

./xt_geoip_build *.csv

mkdir -p /usr/share/xt_geoip/

/bin/cp -rf {BE,LE} /usr/share/xt_geoip/

(cp 경로를 /bin/ 까지 써주지 않으면 overwrite 질문에 다 y눌러줘야함...ㅜ)

Posted by Righ
,

php 명령어로 api 파일을 실행 시켰을 때 정상적인 결과를 출력하지만 curl 명령어 혹은 브라우저로 확인 했을 시에 아무 결과값도 리턴하지 않았다.


/var/log/httpd/ 아래의 에러로그 확인 결과 


sudo: no tty present and no askpass program specified


라는 에러 로그를 확인 하였다.


이 때 브라우저로 php 파일을 여는 user가 누구인지 확인 해야하는데, 처음에는 nobody로 접속하는 것으로 추측하고 nobody 계정에 권한을 주어야하나 고민 했으나 


echo shell_exec("whoami");


로 확인 하였을 때 apache user로 접근 하는 것을 확인 할 수 있었다.


따라서 


/etc/sudoers


파일 맨 아래 줄에


apache ALL=(ALL) NOPASSWD:ALL


를 추가하여 apache에서 sudo를 사용하여 모든 명령어를 사용할 수 있도록 설정하였다. 또는 /etc/sudoers.d

폴더 아래에 파일을 생성하여 위의 라인을 추가하였다.

Posted by Righ
,

테스트는 C# 기반의 ASP.NET MVC 에서!

[참고 : http://j07051.tistory.com/556]


(test 하기 전에 Global.asax.cs 파일에서 초기 경로 수정해 줌. 안하고 url에 경로 치고 들어가도 되긴 하는데 귀찮아서....

url 경로 치고 들어가려면 테스트 url 뒤에 MaliciousCodeDetection)



Global.asax.cs 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Routing;


namespace testProject

{

    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 

    // visit http://go.microsoft.com/?LinkId=9394801


    public class MvcApplication : System.Web.HttpApplication

    {

        public static void RegisterRoutes(RouteCollection routes)

        {

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            routes.MapRoute(

                "Default",                                              // Route name

                "{controller}/{action}/{id}",                           // URL with parameters

                new { controller = "MaliciousCodeDetection", action = "Index", id = "" }  // Parameter defaults

            );


        }


        protected void Application_Start()

        {

            RegisterRoutes(RouteTable.Routes);

        }

    }

}



/Views/MaliciousCodeDetection/Index.aspx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>MaliciousCodeDetection</title>

</head>

<body>

    <div>

       <div>

           VirusTotal

       </div>

       <form action="/MaliciousCodeDetection/callVirusTotalAPI">

           <div>

               <input type="hidden" name="function" value="/url/report" />

               <input type="hidden" name="method" value="GET" />

               <input name="url" type="text"/>&nbsp<input type="submit" value="scan"/>

           </div>

           <div>

               <%=ViewData["VirusTotalResult"]%>

           </div>

       </form>

    </div>

</body>

</html>




/Controllers/MaliciousCodeDetectionController.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Mvc.Ajax;

using System.Net;

using System.Text;

using System.IO;

using System.Web.Script.Serialization;


namespace moveDB.Controllers

{

    public class MaliciousCodeDetectionController : Controller

    {


        String virusTotalPrivateAPIKey = "==YOUR API KEY HERE==";

        String virusTotalURL = "https://www.virustotal.com/vtapi/v2";

        Dictionary<string, string> virusTotalParam = new Dictionary<string, string>();

        Dictionary<string, string> apiOptions = new Dictionary<string, string>()

        {

            {"/url/scan","&url="},

            {"/url/report","&resource="}

        };

        


        public MaliciousCodeDetectionController()

        {

            this.virusTotalParam["apikey"] = virusTotalPrivateAPIKey;

        }



        public ActionResult Index()

        {

            ViewData["VirusTotalResult"] = "default";

            return View();

        }


        public ActionResult callVirusTotalAPI(string function , string method, string url)

        {

            string response = this.CallApi(function, method, url);        //api call 하고 결과 받아옴


            ViewData["VirusTotalResult"] = this.buildHTML(response);  //받아온 결과 출력 형식을 지정함

            

            return View("Index");

        }



        public string CallApi(string function, string method, string url)

        {


            string response;


            if (method.Equals("GET"))

            {

                response = SendWebGetRequest(function, url);

            }

            else

            {

                response = "Undefined Submit Method";

            }


            return response;


        }


        public object json2obj(string st)

        {

            JavaScriptSerializer deserializer = new JavaScriptSerializer();

            return deserializer.Deserialize<object>(st);

        }


        public string obj2json(object obj)

        {

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return serializer.Serialize(obj);

        }


        private string SendWebGetRequest(string function, string url)

        {

            string strUri = this.virusTotalURL + function + "?apikey=" + this.virusTotalPrivateAPIKey + this.apiOptions[function] + url;

            WebRequest wb = WebRequest.Create(strUri);

            wb.ContentType = @"application/json-rpc";

            wb.Credentials = CredentialCache.DefaultCredentials;

            wb.Method = "GET";


            HttpWebResponse response = (HttpWebResponse)wb.GetResponse();

            Stream dataStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(dataStream);

            string responseFromServer = reader.ReadToEnd();

            return responseFromServer;

        }


        private string buildHTML(string resource)

        {

            string html_body = "";


            Dictionary<string, object> response_dic = (Dictionary<string, object>)(json2obj(resource));

            Dictionary<string, object> scans_dic = (Dictionary<string, object>)response_dic["scans"];

            KeyValuePair<string, object> component_dic;

            KeyValuePair<string, object> result_dic;


            foreach (object scan_result in scans_dic)

            {

                component_dic = (KeyValuePair<string, object>)scan_result;

                html_body += "<b>" + component_dic.Key.ToString() + "</b><br />";


                foreach (object component_result in (Dictionary<string, object>)component_dic.Value)

                {

                    result_dic = (KeyValuePair<string, object>)component_result;

                    html_body += result_dic.Key.ToString() + " : " + result_dic.Value.ToString() + "<br />";

                }

            }

            return html_body;

        }

    }

}









Posted by Righ
,