Exemplo n.º 1
0
/***
Add a POST form field to a HTTP context.
@function :addPostData
@tparam string name name of the field
@tparam string value value of the field 
*/
static int httpc_addPostData(lua_State *L) {
	httpcContext *context = lua_touserdata(L, 1);
	char *name = (char*)luaL_checkstring(L, 2);
	char *value = (char*)luaL_checkstring(L, 3);
	
	httpcAddPostDataAscii(context, name, value);
	
	return 0;
}
Exemplo n.º 2
0
Result http_haxx(char *requrl, u8 *cert, u32 certsize, targeturlctx *first_targeturlctx)
{
	Result ret=0;
	httpcContext context;
	u32 *linearaddr = NULL;
	Handle httpheap_sharedmem_handle=0;
	Handle ropvmem_sharedmem_handle=0;
	Handle httpc_sslc_handle = 0;
	u32 i;

	ret = httpcOpenContext(&context, HTTPC_METHOD_POST, requrl, 1);
	if(ret!=0)return ret;

	ret = httpcAddPostDataAscii(&context, "form_name", "form_value");
	if(ret!=0)
	{
		httpcCloseContext(&context);
		return ret;
	}

	//Locate the physmem for the httpc sharedmem. With the current cmpblock, there can only be one POST struct that was ever written into sharedmem, with the name/value from above.
	printf("Searching for the httpc sharedmem in physmem...\n");
	ret = locate_sharedmem_linearaddr(&linearaddr);
	if(ret!=0)
	{
		printf("Failed to locate the sharedmem in physmem.\n");
		httpcCloseContext(&context);
		return ret;
	}

	printf("Writing the haxx to physmem...\n");
	ret = writehax_sharedmem_physmem(linearaddr);
	if(ret!=0)
	{
		printf("Failed to setup the haxx.\n");
		httpcCloseContext(&context);
		return ret;
	}

	printf("Triggering the haxx...\n");
	ret = _httpcCloseContext(&context, &httpheap_sharedmem_handle, &ropvmem_sharedmem_handle, &httpc_sslc_handle);
	if(R_FAILED(ret))
	{
		printf("httpcCloseContext returned 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	httpheap_sharedmem = (vu32*)mappableAlloc(httpheap_size);
	if(httpheap_sharedmem==NULL)
	{
		ret = -2;
		svcCloseHandle(httpheap_sharedmem_handle);
		svcCloseHandle(ropvmem_sharedmem_handle);
		svcCloseHandle(httpc_sslc_handle);
		return ret;
	}

	ropvmem_sharedmem = (vu32*)mappableAlloc(ropvmem_size);
	if(ropvmem_sharedmem==NULL)
	{
		ret = -3;
		mappableFree((void*)httpheap_sharedmem);
		svcCloseHandle(httpheap_sharedmem_handle);
		svcCloseHandle(ropvmem_sharedmem_handle);
		svcCloseHandle(httpc_sslc_handle);
		return ret;
	}

	if(R_FAILED(ret=svcMapMemoryBlock(httpheap_sharedmem_handle, (u32)httpheap_sharedmem, MEMPERM_READ | MEMPERM_WRITE, MEMPERM_READ | MEMPERM_WRITE)))
	{
		svcCloseHandle(httpheap_sharedmem_handle);
		mappableFree((void*)httpheap_sharedmem);
		httpheap_sharedmem = NULL;

		svcCloseHandle(ropvmem_sharedmem_handle);
		mappableFree((void*)ropvmem_sharedmem);
		ropvmem_sharedmem = NULL;

		svcCloseHandle(httpc_sslc_handle);

		printf("svcMapMemoryBlock with the httpheap sharedmem failed: 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	if(R_FAILED(ret=svcMapMemoryBlock(ropvmem_sharedmem_handle, (u32)ropvmem_sharedmem, MEMPERM_READ | MEMPERM_WRITE, MEMPERM_READ | MEMPERM_WRITE)))
	{
		svcUnmapMemoryBlock(httpheap_sharedmem_handle, (u32)httpheap_sharedmem);
		svcCloseHandle(httpheap_sharedmem_handle);
		mappableFree((void*)httpheap_sharedmem);
		httpheap_sharedmem = NULL;

		svcCloseHandle(ropvmem_sharedmem_handle);
		mappableFree((void*)ropvmem_sharedmem);
		ropvmem_sharedmem = NULL;

		svcCloseHandle(httpc_sslc_handle);

		printf("svcMapMemoryBlock with the ropvmem sharedmem failed: 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	printf("Finishing haxx setup with sysmodule memory...\n");
	ret = setuphaxx_httpheap_sharedmem(first_targeturlctx);

	if(R_FAILED(ret))
	{
		printf("Failed to finish haxx setup: 0x%08x.\n", (unsigned int)ret);
	}
	else
	{
		printf("Finalizing...\n");
	}

	svcUnmapMemoryBlock(httpheap_sharedmem_handle, (u32)httpheap_sharedmem);
	svcCloseHandle(httpheap_sharedmem_handle);
	mappableFree((void*)httpheap_sharedmem);
	httpheap_sharedmem = NULL;

	svcUnmapMemoryBlock(ropvmem_sharedmem_handle, (u32)ropvmem_sharedmem);
	svcCloseHandle(ropvmem_sharedmem_handle);
	mappableFree((void*)ropvmem_sharedmem);
	ropvmem_sharedmem = NULL;

	if(R_FAILED(ret))
	{
		svcCloseHandle(httpc_sslc_handle);
		return ret;
	}

	printf("Running setup with sslc...\n");
	ret = setuphax_http_sslc(httpc_sslc_handle, cert, certsize);

	svcCloseHandle(httpc_sslc_handle);//Normally sslcExit should close this, but close it here too just in case.

	if(R_FAILED(ret))
	{
		printf("Setup failed with sslc: 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	printf("Testing httpc with non-targeted URLs...\n");

	for(i=0; i<2; i++)
	{
		ret = httpcOpenContext(&context, HTTPC_METHOD_POST, requrl, 1);
		if(R_FAILED(ret))
		{
			printf("httpcOpenContext returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			return ret;
		}

		ret = httpcAddRequestHeaderField(&context, "User-Agent", "ctr-httpwn/"VERSION);
		if(R_FAILED(ret))
		{
			printf("httpcAddRequestHeaderField returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			httpcCloseContext(&context);
			return ret;
		}

		ret = httpcAddPostDataAscii(&context, "form_name", "form_value");
		if(R_FAILED(ret))
		{
			printf("httpcAddPostDataAscii returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			httpcCloseContext(&context);
			return ret;
		}

		ret = httpcCloseContext(&context);
		if(R_FAILED(ret))
		{
			printf("httpcCloseContext returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			return ret;
		}
	}

	return 0;
}