Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // myFirstDll.cpp : Defines the exported functions for the DLL application.
  2. //
  3.  
  4. //set includes
  5. #include "stdafx.h"
  6. #include <iostream>
  7. #include <fstream>
  8.  
  9. #include <Windows.h>
  10. #include <Authif.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <ctime>
  14. #include <string>
  15.  
  16. #define _CRT_SECURE_NO_WARNINGS
  17. void logger(const char * msg) //logger function --> Write to a log
  18. {
  19. #pragma warning(push)
  20. #pragma warning(disable:4996)
  21. FILE * fp = fopen("C:/Temp/NPS.log.txt", "a");
  22. if (fp)
  23. {
  24. fprintf(fp, "%s\n", msg);
  25. fclose(fp);
  26. }
  27. #pragma warning(pop)
  28. }
  29.  
  30.  
  31. DWORD WINAPI RadiusExtensionProcess2(
  32. _Inout_ PRADIUS_EXTENSION_CONTROL_BLOCK pECB
  33. )
  34. {
  35. #pragma warning(disable: 4996)
  36. if (pECB != NULL)
  37. {
  38. if (pECB->rcRequestType == rcAccessRequest) //check if the request is a access request
  39. {
  40. RADIUS_ATTRIBUTE_ARRAY * pAR = pECB->GetRequest(pECB); //get the attribute array
  41. if (pAR != NULL) //check if the attribute array is not empty
  42. {
  43. //Initialize some variables
  44. char * username = NULL;
  45. char * password = NULL;
  46. char * uniqueId = NULL;
  47. char * clientIp = NULL;
  48.  
  49. //get the size of the attribute array
  50. DWORD size = pAR->GetSize(pAR);
  51.  
  52. //pre-init the attirbute pointer
  53. const RADIUS_ATTRIBUTE * pRA;
  54.  
  55. //Loop through each object in attribute array
  56. for (DWORD iAR = 0; iAR < size; iAR++)
  57. {
  58. //Get the attribute from the array
  59. pRA = pAR->AttributeAt(pAR, iAR);
  60. if (pRA != NULL) //check if the attribute is not empty
  61. {
  62. if (pRA->dwAttrType == ratUserName) //get username
  63. {
  64. username = (char *)pRA->lpValue;
  65. }
  66. if (pRA->dwAttrType == ratUniqueId)
  67. {
  68. uniqueId = (char *)pRA->dwValue;;
  69. }
  70. if (pRA->dwAttrType == ratUserPassword)
  71. {
  72. password = (char *)pRA->lpValue;
  73. }
  74. if (pRA->dwAttrType == ratCallingStationId)
  75. {
  76. clientIp = (char *)pRA->dwValue;
  77. }
  78. }
  79. }
  80.  
  81. //write the result to the log file
  82. char buft[2048];
  83. sprintf(buft, "Recieved Request (ID:%d) for user: %s, pass: %s", uniqueId, username, password);
  84. logger(buft);
  85.  
  86. }
  87. else if (pECB->rcRequestType == rcAccountingRequest)
  88. {
  89. pECB->SetResponseType(pECB, rcAccountingResponse);
  90. }
  91. else
  92. {
  93. pECB->SetResponseType(pECB, rcUnknown);
  94. }
  95.  
  96. }
  97. }
  98. return NO_ERROR; //Exit the complete function
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement