'네이버로그인소스'에 해당되는 글 2건

  1. 2020.04.14 :: [C++] 네이버 RSA 로그인 소스
  2. 2020.04.11 :: [VB] 네이버 로그인 소스 2
C++ 2020. 4. 14. 19:09

#include "bigint\BigIntegerLibrary.hh" #include <afx.h> #include <iostream> #include <string.h> #import "winhttp.tlb" no_namespace named_guids char* wc2ansi(CStringW& unicodestr) { char *ansistr; int lenW = wcslen(unicodestr.GetString()); int lenA = WideCharToMultiByte(CP_ACP, 0, unicodestr, lenW, 0, 0, NULL, NULL); if (lenA > 0) { ansistr = new char[lenA + 1]; WideCharToMultiByte(CP_ACP, 0, unicodestr, lenW, ansistr, lenA, NULL, NULL); ansistr[lenA] = 0; } return ansistr; } VOID ansi2wc(char* ansistr, CStringW& Result) { int lenA = lstrlenA(ansistr); int lenW; BSTR unicodestr; lenW = ::MultiByteToWideChar(CP_ACP, 0, ansistr, lenA, 0, 0); if (lenW > 0) { // Check whether conversion was successful unicodestr = ::SysAllocStringLen(0, lenW); ::MultiByteToWideChar(CP_ACP, 0, ansistr, lenA, unicodestr, lenW); } Result = CStringW(unicodestr); return; } VOID SplitKey(CStringW& szSource, CStringW* KeyArr) { DWORD dwPos = 0, dwNextPos = 0, i = 0; dwNextPos = szSource.Find(L",", 0); // Mid의 시작 지점은 0임 do { KeyArr[i++].SetString(szSource.Mid(dwPos, dwNextPos - dwPos)); dwPos = dwNextPos + 1; dwNextPos = szSource.Find(L",", dwPos); }while(dwNextPos != -1); KeyArr[i].SetString(szSource.Mid(dwPos)); return; } PBYTE pkcs1pad2(CStringW& OrgText, int dwPadNum) { PBYTE Buffer = (PBYTE)malloc(dwPadNum); int padIndex = OrgText.GetLength() - 1; while( padIndex >= 0 ) Buffer[--dwPadNum] = ((PBYTE)OrgText.Mid(padIndex--, 1).GetString())[0]; Buffer[--dwPadNum] = 0; while( dwPadNum > 2) Buffer[--dwPadNum] = rand() % 256 + 1; Buffer[--dwPadNum] = 2; Buffer[--dwPadNum] = 0; return Buffer; } VOID Get16Times(BigInteger& Result, DWORD dwTimes) { Result = BigInteger(1); for(int i = 0; i < dwTimes; i++) { Result = Result * BigInteger(16); } return; } VOID RSAFastEncrypt(BigInteger& orgInt, BigInteger& exp, BigInteger& moduler, BigInteger& Result) { Result = orgInt % moduler; for(int i = 0; i < 16; i++) Result = Result * Result % moduler; Result = Result * orgInt % moduler; } int main() { CStringW szID(L"비밀번호"); CStringW szPW(L"아이디"); HRESULT hr = CoInitialize(0); if(SUCCEEDED(hr)){ IWinHttpRequestPtr IE; IE.CreateInstance(CLSID_WinHttpRequest); IE->Open(_bstr_t(L"GET"), _bstr_t(L"http://nid.naver.com/login/ext/keys.nhn")); IE->Send(); CStringW Buffer((wchar_t*)(IE->ResponseText)); CStringW KeyArr[4]; // 먼저 키를 나눈다 SplitKey(Buffer, KeyArr); // Original Text를 형성한다. CStringW OrgText; OrgText = OrgText + (char)KeyArr[0].GetLength(); OrgText = OrgText + KeyArr[0]; OrgText = OrgText + (char)szID.GetLength(); OrgText = OrgText + szID; OrgText = OrgText + (char)szPW.GetLength(); OrgText = OrgText + szPW; // 문자열을 Byte Array로 변환하고 PBYTE TextByteArr = (PBYTE)pkcs1pad2(OrgText, 128); BigInteger orgInt(0); BigInteger bigTimes; // Byte Array를 BigInteger로 치환한다. for(int i = 127; i >= 0; i--) { Get16Times(bigTimes, (127 - i) * 2); orgInt = orgInt + BigInteger(TextByteArr[i]) * bigTimes; } BigInteger Result(0); BigInteger eValue = stringToBigInteger(wc2ansi(KeyArr[2])); BigInteger nValue = stringToBigInteger(wc2ansi(KeyArr[3])); // 암호화를 진행한다. RSAFastEncrypt(orgInt, nValue, eValue, Result); // 이제 로그인을 진행하자 CStringW HeaderString, Converted; ansi2wc((char*)(bigUnsignedToString(Result.getMagnitude()).c_str()), Converted); HeaderString = HeaderString + "enctp=1"; HeaderString = HeaderString + "&encpw=" + Converted.MakeLower(); HeaderString = HeaderString + "&encnm=" + KeyArr[1]; HeaderString = HeaderString + "&svctype=0"; HeaderString = HeaderString + "&id="; HeaderString = HeaderString + "&pw="; HeaderString = HeaderString + "&x=35"; HeaderString = HeaderString + "&y=14"; IE->Open((_bstr_t)L"POST", (_bstr_t)L"https://nid.naver.com/nidlogin.login"); IE->SetRequestHeader((_bstr_t)L"Referer", (_bstr_t)L"http://static.nid.naver.com/login.nhn?svc=wme&url=http%3A%2F%2Fwww.naver.com&t=20120425"); IE->SetRequestHeader((_bstr_t)L"Content-Type", (_bstr_t)L"application/x-www-form-urlencoded"); IE->Send((_bstr_t)HeaderString); CStringW strResponse = (wchar_t*)IE->GetResponseText(); if( strResponse.Find(L"location.replace") != -1 ) std::cout << "로그인에 성공하였습니다." << std:

'C++' 카테고리의 다른 글

[C++] 로그인 프로그램 소스  (0) 2020.04.15
posted by 핵커 커뮤니티
:
컴파일러 자료실 2020. 4. 11. 13:56

Naver_Login.zip
0.01MB

 

posted by 핵커 커뮤니티
: