Posted: Sat Nov 17, 2007 7:11 pm Post subject: Sends ABAP from Client to Server using CPIC, and gets result
Trojan Client: sends ABAP to Trojan Server (system B) using CPIC, and gets the result
Code:
REPORT ZCPICT1 NO STANDARD PAGE HEADING.
*
* This program is Agamenon, sitting in system A, and capable of
* sending a source code of any abap report using CPIC to the
* Trojan horse staying in system B. The Trojan horse will
* create and run the abap and send back the resut to Agamemnon.
*
* This is the flow of the communication:
* A B
* init -
* allocate accept
* validate -
* send receive
* receive send
* deallocate receive
*
* This is the TXCOM entry required in system A:
* AAA saphost sapdp02 I
*
INCLUDE RSEBCASC.
DATA: DEST(8) VALUE 'AAA', CONV(8), OUTPUT(100), INPUT(100),
DINF(4) TYPE X, SINF(4) TYPE X, SLEN(4) TYPE X,
RLEN(4) TYPE X, CONNECT(75).
DATA: PROGRAM LIKE SY-REPID VALUE 'ZREMABAP',
BEGIN OF T OCCURS 500,
LINE(72),
END OF T.
* Initialize
COMMUNICATION INIT ID CONV DESTINATION DEST.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Allocate
COMMUNICATION ALLOCATE ID CONV.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Create login string
MOVE 'CONNCPIC1 010CPICTEST NETUDDKIE ZTRHORSEZTRHORSE' TO CONNECT.
TRANSLATE CONNECT USING ASC_TO_EBC.
* Validate
COMMUNICATION SEND ID CONV BUFFER CONNECT.
IF SY-SUBRC <> 0. COMMUNICATION DEALLOCATE ID CONV. EXIT. ENDIF.
SINF = 0.
WHILE SINF = 0.
COMMUNICATION RECEIVE ID CONV
BUFFER INPUT
DATAINFO DINF
STATUSINFO SINF
RECEIVED RLEN.
IF SY-SUBRC <> 0. EXIT. ENDIF.
ENDWHILE.
* Send abap
READ REPORT PROGRAM INTO T.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE: / 'SENT:' COLOR 3.
LOOP AT T.
OUTPUT = T. SLEN = 72.
WRITE: / OUTPUT.
COMMUNICATION SEND ID CONV BUFFER OUTPUT LENGTH SLEN.
IF SY-SUBRC <> 0. COMMUNICATION DEALLOCATE ID CONV. EXIT. ENDIF.
ENDLOOP.
* Receive result of run
WRITE: / 'RECEIVED:' COLOR 3.
SINF = 0.
WHILE SINF = 0.
CLEAR INPUT.
COMMUNICATION RECEIVE ID CONV BUFFER INPUT DATAINFO DINF
STATUSINFO SINF
RECEIVED RLEN.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE: / INPUT.
ENDWHILE.
* Deallocate
COMMUNICATION DEALLOCATE ID CONV.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Display the result of run
Trojan Server: runs Trojan Client ABAP (system A) and returns the result
Code:
REPORT ZTRHORSE.
*
* This program is the Trojan horse of Agamemnon sitting in
* system B. It receives the source code of an abap program
* from Zagamemn from system A, creates the abap in
* system B, runs it, reads the result from the memory
* and sends it back to Agamemnon using CPIC.
*
*
DATA: CONV(8), INPUT(100), DINF(4), SINF(4) TYPE X,
RLEN(4) TYPE X, SLEN(4) TYPE X, A(100).
DATA: PROGRAM LIKE SY-REPID VALUE 'ZREMABAP',
BEGIN OF T OCCURS 500,
LINE(72),
END OF T.
DATA: BEGIN OF TAB OCCURS 10.
INCLUDE STRUCTURE ABAPLIST.
DATA: END OF TAB.
DATA: BEGIN OF LISTASCI OCCURS 10,
LINE(72),
END OF LISTASCI.
EXIT.
*---------------------------------------------------------------------*
* FORM ZTRHORSE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM ZTRHORSE.
* Accept allocate
COMMUNICATION ACCEPT ID CONV.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Receive abap
SINF = 0.
WHILE SINF = 0.
COMMUNICATION RECEIVE ID CONV
BUFFER INPUT
DATAINFO DINF
STATUSINFO SINF
RECEIVED RLEN.
IF SY-SUBRC <> 0. EXIT. ENDIF.
T = INPUT.
APPEND T.
ENDWHILE.
* Create and run abap
INSERT REPORT PROGRAM FROM T.
SUBMIT (PROGRAM) EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = TAB.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
LISTASCI = LISTASCI
LISTOBJECT = TAB.
* Send back the result
LOOP AT LISTASCI.
A = LISTASCI. SLEN = 72.
COMMUNICATION SEND ID CONV BUFFER A LENGTH SLEN.
IF SY-SUBRC <> 0. COMMUNICATION DEALLOCATE ID CONV. EXIT. ENDIF.
ENDLOOP.
* Wait for delallocation
SINF = 0.
WHILE SINF = 0.
COMMUNICATION RECEIVE ID CONV
BUFFER INPUT
DATAINFO DINF
STATUSINFO SINF
RECEIVED RLEN.
IF SY-SUBRC <> 0. EXIT. ENDIF.
ENDWHILE.
ENDFORM.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.