How to Pack a variable with p32() ik python? - exploit

I would like to pack a variable and also multiply it .But i can't did it properly can anyone help me to fix it
from pwn import *
p= process (./format2)
target = "deadbeef"
payload = p32("A"*64)
payload += p32(target)
p.sendline(payload)
p.interactive()

Your payload should be:
payload = b"A" * 64 + p32(0xdeadbeef)
p8, p32 and p64 should have a non-negative integer type data as argument. For example:
p8(22), p32(11), p64(0xdead)

Related

Nnet in caret, basic structure

I'm very new to caret package and nnet in R. I've done some projects related to ANN with Matlab before, but now I need to work with R and I need some basic help.
My input dataset has 1000 observations (in rows) and 23 variables (in columns). My output has 1000 observations and 12 variables.
Here are some sample data that represent my dataset and might help to understand my problem better:
input = as.data.frame(matrix(sample(1 : 20, 100, replace = TRUE), ncol = 10))
colnames(input) = paste ( "X" , 1:10, sep = "") #10 observations and 10 variables
output = as.data.frame(matrix(sample(1 : 20, 70, replace = TRUE), ncol = 7))
colnames(output) = paste ( "Y" , 1:7, sep = "") #10 observations and 7 variables
#nnet with caret:
net1 = train(output ~., data = input, method= "nnet", maxit = 1000)
When I run the code, I get this error:
error: invalid type (list) for variable 'output'.
I think I have to add all output variables separately (which is very annoying, especially with a lot of variables), like this:
train(output$Y1 + output$Y2 + output$Y3 + output$Y4 + output$Y5 +
output$Y6 + output$Y7 ~., data = input, method= "nnet", maxit = 1000)
This time it runs but I get this error:
Error in [.data.frame(data, , all.vars(Terms), drop = FALSE) :
undefined columns selected
I try to use neuralnet package, with the code below it works perfectly but I still have to add output variables separately :(
net1 = neuralnet(output$Y1 + output$Y2 + output$Y3 + output$Y4 +
output$Y5 + output$Y6 + output$Y7 ~., data = input, hidden=c(2,10))
p.s. since these sample data are created randomly, the neuralnet cannot converge, but in my real data it works well (in comparison to Matlab ANN)
Now, if you could help me with a way to put output variables automatically (not manually), it solves my problem (although with neuralnet not caret).
use the str() function and ascertain that its a data frame looks like you are inputting a list to the train function. This may be because of a transformation you are doing before to output.
str(output)
Without a full script of earlier steps its difficult to understand what is going on.
After trying different things and searches, I finally found a solution:
First, we must use as.formula to show the relation between our input and output. With the code below we don't need to add all the variables separately:
names1 <- colnames(output) #the name of our variables in the output
names2 = colnames(input) #the name of our variables in the input
a <- as.formula(paste(paste(names1,collapse='+', sep = ""),' ~ '
,paste(names2,collapse='+', sep = "")))
then we have to combine our input and output in a single data frame:
all_data = cbind(output, input)
then, use neuralnet like this:
net1 = neuralnet(formula = a, data = all_data, hidden=c(2,10))
plot(net1)
This is also work with the caret package:
net1 = train(a, data = all_data, method= "nnet", maxit = 1000)
but it seems neuralnet works faster (at least in my case).
I hope this helps someone else.

How should I use an array (or tuple) as key and values for a Numba typed dictionary?

I have the following code that attempts to store a key-value pair into a numba dictionary. The official page of Numba says that the new typed dictionary supports array as the key, but I could not get it to work.
The error message says that the key cannot be hash.
Any idea how to get this working?
In [7]: from numba.typed import Dict
...: from numba import types
...: import numpy as np
In [15]: dd = Dict.empty(key_type=types.int32[::1], value_type=types.int32[::1],)
In [16]: key = np.asarray([1,2,3], dtype=np.int32)
In [17]: dd[key] = key
Error Message:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'hash' of type array(int32, 1d, C)
EDIT:
I am probably missing something. I could use types.UniTuple in the interpreter (without the #jit decorator). However, when I put the following function into a script a.py and run it with command "python a.py", I got the UniTuple not found error.
#jit(nopython=True)
def go_fast2(date, starttime, id, tt, result): # Function is compiled and runs in machine code
prev_record = Dict.empty(key_type=types.UniTuple(types.int64, 2), value_type=types.UniTuple(types.int64, 3),)
for i in range(1, length):
key = np.asarray([date[i], id[i]], dtype=np.int64)
thistt = tt[i]
thistime = starttime[i]
if key in prev_record:
prev_time = prev_record[key][0]
prev_tt = prev_record[key][1]
prev_res = prev_record[key][2]
if thistt == prev_tt and thistime - prev_time <= 30 * 1000 * 1000: # with in a 10 seconds window
result[i] = prev_res + 1
else:
result[i] = 0
prev_record[key] = np.asarray((thistime, thistt, result[i]), dtype=np.int64)
else:
result[i] = 0
prev_record[key] = np.asarray((thistime, thistt, result[i]), dtype=np.int64)
return
The current documentation says that:
Acceptable key/value types include but are not limited to: unicode
strings, arrays, scalars, tuples.
The wording does make it seem like you might be able to use an array as a key type, but that is incorrect as an array is not hashable because it is mutable. It wouldn't work with a standard python dict either. You could convert the array to a tuple and that would work:
dd = Dict.empty(
key_type=types.UniTuple(types.int64, 3),
value_type=types.int64[::1],)
key = np.asarray([1,2,3], dtype=np.int64)
dd[tuple(key)] = key
Note that the int32 dtype you were using previously won't work on 64-bit machines since the tuple of int32s will be automatically converted to int64 when calling tuple() on the array.
The other issue is that a tuple has a fixed size, so you couldn't use arrays of arbitrary size as the key.

Operate with large numbers in LibreOffice BASIC

I'm trying to operate the MOD of a number but it returns overflow data type.
This operation works:
VariableDouble = 2147483647 - (97 * (2147483647 \ 97))
MsgBox VariableDouble
This operation returns error:
VariableDouble = 2147483648 - (97 * (2147483648 \ 97))
MsgBox VariableDouble
Shouldn't be Double data type larger than Long one? Of course, variable declaration is as follows: Dim VariableDouble As Double.
It happens the same if I use the built-in operator MOD: a MOD b.
I need to do operations with 10 digits numbers. Is there a way I can do this using BASIC? What is happening?
I found a solution making my own MOD implementation [partially] with an iterative bucle. It works —I didn't test it using numbers with a lenght greater than 50 digits, though—, so this is the code:
Dim LargeNumber As Double
Dim result As Integer
Dim dividend As Integer
Dim index As Integer
For index = 1 To Len(LargeNumber)
dividend = result & Mid(LargeNumber, index, 1)
result = dividend Mod 97
Next
It seems BASIC can't operate with large numbers, despite it can save them into variables. An another solution would be to call Python externally (API can do that). Python is awesome, however I need to keep the portability of this database for several systems (some use Windows OS so won't have Python preinstalled).
From https://wiki.openoffice.org/wiki/Using_Python_on_Windows: "If you do not customize the installation, Python-UNO bridge is installed as default on recent version." So a dependence on Python should be portable.
def big_numbers():
dividend = 12345678901234567890123456789012345678901234567890
divisor = 97
modulus = dividend % divisor
rounded_val = modulus * divisor
result = dividend - rounded_val
oDoc = XSCRIPTCONTEXT.getDocument() # the current Writer document
oVC = oDoc.getCurrentController().getViewCursor()
output = ("%d - (%d * (%d \ %d)) = %d\n" %
(dividend, divisor, dividend, divisor, result))
oDoc.getText().insertString(oVC, output, False)
g_exportedScripts = (big_numbers,)
See https://wiki.openoffice.org/wiki/Python_as_a_macro_language for how to run this code.
Related: https://forum.openoffice.org/en/forum/viewtopic.php?t=39854.

Selenium IDE: how to append int variable after string

I have just started using selenium IDE and I am trying to append a integer value after a constant string:
variable x = string
variable y = integer
append string+integer
anyone so kind to help me out?
I have never used java in my life.
Thank you!
You can store the values in another string like:
String name = "test";
int number = 1;
String combined = name+number;

MATLAB wchar_t Equivalent Type

The C-Code is stored in a DLL. I can load the DLL in MATLAB with the loadlibrary function. I am having trouble passing the wchar_t*[] parameter to the function. I do not know how to create this data type in MATLAB. Does anyone know how to create this type to pass to the calllib function?
MATLAB Code:
loadlibrary('test.dll', 'test.h');
str = '0';
ptr = libpoiner('voidPtrPtr', [int8(str) 0])
calllib('test.dll', 'testFunction', ptr) %this parameter does not match the wchar*[] type
outVal = ptr.Value
C-Code:
void testFunction(wchar_t* str[])
{
str[0] = L"test";
}
Output:
MATLAB allows the function to complete. The outVal variable is filled with garbage values.
If you are able to modify the C header files, you may try the following:
Adjust the header file to convert all wchar_t * to unsigned short *.
On the MATLAB side, the corresponding type would then be a uint16 array.
You could then typecast the uint16 array to char.
I figured it out. I changed the MATLAB code to the following:
loadlibrary('test.dll', 'test.h');
str = '0';
ptr = libpoiner('voidPtrPtr', [uint16(str) 0])
calllib('test.dll', 'testFunction', ptr) %this parameter does not match the wchar*[] type
outVal = ptr.Value
expectedOutput = char(outVal); %convert to ASCII
It outputs the values in decimal which confused me. When I converted them to ASCII, everything made sense.